手记

python遍历的三种方式

1、直接遍历

>>> a = "a b c d e"'a b c d e'>>> a_list = a.split()>>> a_list['a', 'b', 'c', 'd', 'e']>>> for i in a_list:...     print i...abcde>>>

2、通过索引遍历

>>> for i in range(len(a_list)):...     print a_list[i]...abcde>>>

3、通过切片遍历

>>> a_list['a', 'b', 'c', 'd', 'e']>>> a_list[::1]['a', 'b', 'c', 'd', 'e']>>>

0人推荐
随时随地看视频
慕课网APP