1.字符串依次取值
students = [‘egon’, ‘lxx’, ‘alex’]
i = 0
while i < 3:
print(students[i])
i += 1
2.针对循环取值操作,while循环并不擅长,于是python提供一个专门循环取值操作:for循环
students = [‘egon’, ‘lxx’, ‘alex’]
for x in students: # 有几个值就循环几次
print(x)
dic={‘name’:’egon’,’age’:18,’sex’:’male’}
for aaa in dic: # 从字典里取出的默认是key,
print(aaa,dic[aaa])
for x in ‘egon’:
print(x)
count = 0
while count < 3:
print(‘======’)
print(‘hello world’)
print(‘======’)
count+=1
for x in [‘a’,’b’,’c’]: # x=’c’
print(‘======’)
print(‘hello world’)