Python 如何在shell中去掉逗号和括号

Python 如何在shell中去掉逗号和括号,python,python-3.x,Python,Python 3.x,好的,在进行了大量搜索之后,我决定问一个问题,我尝试了打印[0],但我发现了错误 Traceback (most recent call last): 文件“”,第1行,在 打印[0] TypeError:“内置函数”或“方法”对象不可下标 ['a', 'c', 'e'] [1, 3, 5] 这是我的两个输出,我想去掉逗号和倒逗号,让它看起来像 ace 135 对于带有str的列表: x = ['a','c','e'] str1 = ''.join(x) 对于带有int的列表: x =

好的,在进行了大量搜索之后,我决定问一个问题,我尝试了打印[0],但我发现了错误

Traceback (most recent call last):
文件“”,第1行,在 打印[0] TypeError:“内置函数”或“方法”对象不可下标

 ['a', 'c', 'e']
[1, 3, 5]
这是我的两个输出,我想去掉逗号和倒逗号,让它看起来像

ace
135

对于带有
str
的列表:

x = ['a','c','e']
str1 = ''.join(x)
对于带有
int
的列表:

x = [1,2,3]
str1=''.join(str(y) for y in x)
这应该对你有用

''.join(a)
print ''.join(a)
对于整数列表[1,3,5],首先使用以下命令将元素更改为字符串:

map(lambda x: str(x), [1,3,5])

然后发出与第一行相同的行。然后,如果愿意,可以将其更改回int。

要从列表元素创建字符串,请执行以下操作:

my_list_1 = ['a', 'c', 'e']
my_list_2 = [1, 3, 5]

# The "join" works for both when list's element type is "string" or "int"
list_1_str = ''.join(map(str, my_list_1))
# output: "ace"

list_2_str = ''.join(map(str, my_list_2))
# output: "135"