Converting a list to string in python 2.7
我有一张单子。它被初始化,然后附加。但我跑步时出错了?
1 2 3 4 | xline = [] ---#append ---- print (''.join(xline)) # Convert list into string |
运行时间误差
1 2 | print (''.join(xline)) # Convert list into string TypeError: sequence item 0: expected string, int found |
怎么了?
可以使用
1 | print ''.join([str(x) for x in xline]) |