python_列表_循环遍历

遍历 就是 从头到尾 依次从 列表 中获取数据

  在 循环体内部 针对 每一个元素,执行相同的操作

在 python 中为了提高列表的遍历效率,专门提供的 迭代 iteration 遍历

使用 for 就能实现迭代遍历

语法格式:

1 #for 循环内部使用变量 in 列表
2 name_list = ["zhangsan","lisi","wangwu"]
3 for name in name_list:
4     # 循环内部针对列表元素进行操作
5     print(name)

猜你喜欢

转载自www.cnblogs.com/shao-null/p/9264951.html
今日推荐