加入清单:
>>> ''.join([ str(_) for _ in xrange(10) ])
'0123456789'
join
必须采用迭代。
显然,join
的参数是 [ str(_) for _ in xrange(10) ]
它是 列表内涵。
看看这个:
>>>''.join( str(_) for _ in xrange(10) )
'0123456789'
现在,join
的参数只是 str(_) for _ in xrange(10)
,没有 []
,但是结果是相同的。
为什么? str(_) for _ in xrange(10)
也产生一个列表或迭代?