Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以说我有:
hello = list(xrange(100)) print hello
结果是:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
我需要从列表中删除所有这些空格,这样它就可以像:
1,2,3,4,5,6,7,8,9,10...
由于join需要字符串对象,因此您需要将这些项目显式转换为字符串。例如:
join
hello = ','.join(list(xrange(100))) TypeError: sequence item 0: expected string, int found
所以:
hello = xrange(100) print ''.join([str(n) for n in hello])
请注意,不需要list().
list()