Names= ['Lily', 'Lucy', 'Tom','Lilei']
分别用for循环和white循环将list中的每个名字打印出:Hi, xx!Happy holidays!
for循环:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Names= ['Lily', 'Lucy', 'Tom','Lilei']
for name in Names:
print('Hi, %s!,Happy holidays!' % name)
while循环:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Names= ['Lily', 'Lucy', 'Tom','Lilei']
n=0
while n<=3:
print('Hi, %s!,Happy holidays!' % Names[n])
n=n+1
如果出错,检查代码缩进是否正确,是否混用中英文标点。
网友评论