首页 > 代码库 > 利用range() 控制循环

利用range() 控制循环

s = [‘a‘,‘b‘,‘c‘,‘d‘,‘e‘]

for i in range(len(s)):
...     if i < len(s)-1:
...         print s[i]

a
b
c
d

for i in range(len(s)):
...     if i < len(s)-1:
...         print s[i+1]
...
b
c
d
e

for i in range(len(s)):
...     if i < len(s)-1:
...         print s[i], s[i+1]
...
a b
b c
c d
d e

 

by freemao

FAFU

free_mao@qq.coom