python22 while for 遍历列表

while for 遍历列表

#  while 和 for  变量列表

nums = [1, 2, 3, 4, 5, 6]

# while 遍历

i = 0

print("while遍历")

while i < len(nums):

    print(nums[i])

    i += 1

print("for遍历")

for num in nums:

    print(num)

输出

while遍历

1

2

3

4

5

6

for遍历

1

2

3

4

5

6

 

Process finished with exit code 0

如有疑问,请发邮件:[email protected]


github:https://github.com/wangrui0/

 

猜你喜欢

转载自blog.csdn.net/qq_35524586/article/details/85015418