TypeError: sequence item 0: expected STR instance, int found TypeError: sequence item 0: expected STR instance, int found
List1 =[1,’two’,’three’,4]
print(‘ ‘.join(list1))
I thought it would print 1, two, three, four
The result was an error
Traceback (most recent call last):
File “< pyshell#27>” , line 1, in < module>
print(” “.join(list1))
peerror: sequence item 0: expected STR instance, int found
p> (“.join(list1))
TypeError: sequence item 0: expected STR instance, int found
A list of numbers cannot be converted directly to a string.
Print (” “.join(‘%s’ %id for id in list1))
That is, iterating through the elements of the list, converting them to strings. So I can print 1, 2, 3, 4.
List1 =[1,’two’,’three’,4]
print(‘ ‘.join(list1))
I thought it would print 1, two, three, four
The result was an error
Traceback (most recent call last):
File “< pyshell#27>” , line 1, in < module>
print(” “.join(list1))
peerror: sequence item 0: expected STR instance, int found
p> (“.join(list1))
TypeError: sequence item 0: expected STR instance, int found
A list of numbers cannot be converted directly to a string.
Print (” “.join(‘%s’ %id for id in list1))
That is, iterating through the elements of the list, converting them to strings. So I can print 1, 2, 3, 4.