Python基础之for循环

for循环:用户按照顺序循环可迭代对象的内容

1. for循环字符串

```Python msg = "string" for i in msg: print(i) ``` 执行结果为: ```Python s t r i n g ```

2. for循环列表

```Python lst = ["a", "b", "c"] for i in lst: print(i) ``` 执行结果为: ```Python a b c ```

3. for循环字典

```Python dic = { "name": "yang", "age": 18, "sex": "male" } for key, value in dic.items(): print(key, value) ``` 执行结果为: ```Python name yang age 18 sex male ```
原文地址:https://www.cnblogs.com/yang-wei/p/9630508.html