如何遍历 Python 元组列表?
pythonserver side programmingprogramming更新于 2025/7/9 17:48:17
最简单的方法是使用两个嵌套的 for 循环。外循环获取每个元组,内循环遍历元组中的每个项目。内部 print() 函数 end=’ ‘ 将元组中的所有项目打印在一行中。另一个 print() 在每个元组后引入新行。
示例
L=[(1,2,3), (4,5,6), (7,8,9,10)] for x in L: for y in x: print(y, end=' ') print()
输出
1 2 3 4 5 6 7 8 9 10
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

