Python 循环
2023-09-27 14:24:29 时间
循环
range实现循环
S = [1, 2, 3, 4, 5, 6]
for i in range(0, len(S), 2):
print S[i]
enumerate 实现循环
S = [10, 20, 30]
for (index, value) in enumerate(S):
print index
print value
zip
ta = [1, 2, 3, 4]
tb = [9, 8, 7]
tc = ['a', 'b', 'c']
for (a, b, c) in zip(ta, tb, tc):
print(a, b, c)
'''
(1, 9, 'a')
(2, 8, 'b')
(3, 7, 'c')
'''
ta = [1, 2, 3]
tb = [9, 8, 7]
# cluster
zipped = zip(ta, tb)
print(zipped)
# decompose
na, nb = zip(*zipped)
print(na, nb)
'''
[(1, 9), (2, 8), (3, 7)]
((1, 2, 3), (9, 8, 7))
'''
相关文章
- python的for循环和while循环的一些代码
- 算法Python 输出百分比的方法(Python2输出百分比、Python3输出百分比)
- Python 计时器(秒钟、秒表)
- Python 学习笔记 - for循环: 字典遍历, 分别打印key, value, key:value
- 【华为OD机试真题 python】最大股票收益【2022 Q4 | 100分】
- [tool] Visual Studio Code python配置
- python扩展库numpy中函数meshgrid()的使用[当你想要两个for循环嵌套处理时,就该想到它]
- 119 python高级 - 多线程threading(二)
- 13 python - for循环
- Python: threading.Semaphore & threading.BoundedSemaphore & GIL
- Python自动化运维--系统基础信息模块
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 【Python】打印列表所有元素
- tensorRT使用python进行网络定义
- python 将字符串转换为字典
- Python分支结构和循环结构
- 《Python 3程序开发指南(第2版•修订版)》——2.2 Integral类型
- 基于Python实现可靠数据传输协议【100010493】
- 基于Python(Django)+MongoDB实现的(Web)新闻采集和订阅系统【100010319】
- Python循环结构用法
- python实例 条件和循环语句
- Python 桌面程序教程之 04 持久窗口使用事件循环进行多次读取,更新窗口中的数据(教程含源码)
- 2、递归和循环——跳台阶和变态跳台阶(python版)
- 【Python 基础】For 循环的小例子
- python第二十二课——list函数
- python编程性能之数据替换
- [Python] 循环语句