+ 1

str() Error?

Why I cannot change a list into a string by str() in Python3 Also, how to do it

5th Apr 2018, 7:17 AM
ManYin Cheung
ManYin Cheung - avatar
2 Réponses
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 ' '
5th Apr 2018, 7:21 AM
Bartosz Pieszko
Bartosz Pieszko - avatar
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
5th Apr 2018, 1:12 PM
Markus Kaleton
Markus Kaleton - avatar