一、while循环和for循环
例:依次打印出学生的姓名
#while循环
students=['mike','jack','mary','pat','will','lisa']
idx=0
while idx <len(students):
print(students[idx])
dx +=1
#for循环
students=['mike','jack','mary','pat','will','lisa']
for one in students:
print(one)
二、break和countiue使用方法
#break语句(中止循环)
name_age=[
('a',10),
('b',15),
('c',2),
('d',25),
]
for one in name_age:
name =one[0]
age = one[1]
if name == 'a':
print('找到了,a的年龄为%d'% age)
break
#continue(中止当前循环)
三、注释
#注释
1. 第一种使用#
2. 第二种首尾'''适用于多行
3. 第三种函数doc string(描述函数功能)
def foo():
'This is a doc string.'
return True