+ 1
str() Error?
Why I cannot change a list into a string by str() in Python3 Also, how to do it
2 ответов
0
A =[1,2,3]
S = str(A)
print(S)
The output is already string. But it is formated like list.
If you want to put only values from list to string then:
S = ''.join(str(e) for e in list)
Note that '' is two ' '
0
a =[1,2,3]
b = str(a)
print(b)
if you need it as separated values you can remove the brackets with .replace("[", "")
or if you want all the values to be one long string you can do
a = [1,2,3]
s = ""
for i in a:
i = str(i)
s += i