>>> for ch in 'abcd': ... print ch ... a b c d >>> for ch in 'ancd': ... print ch, ... a n c d
print语句默认会给每一行添加一个换行符,只要在print语句后面添加一个逗号,就能够改变这种行为函数
>>> range(1,4) [1, 2, 3] >>> range(4) [0, 1, 2, 3] >>> range(1,4,2) [1, 3]
>>> for i in range(len(alist)): ... print "%s:%s" % (i,alist[i]) ... 0:tom 1:bob 2:vs 3:cm