for循环:用户按照顺序循环可迭代对象的内容
1. for循环字符串
msg = "string"for i in msg: print(i)
执行结果为:
string
2. for循环列表
lst = ["a", "b", "c"]for i in lst: print(i)
执行结果为:
abc
3. for循环字典
dic = { "name": "yang", "age": 18, "sex": "male"}for key, value in dic.items(): print(key, value)
执行结果为:
name yangage 18sex male