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 ```
posted @ 2018-09-11 21:35  _杨魏  阅读(444)  评论(0编辑  收藏  举报