ccyiming
2021-05-09 10:01
numbersInList = [x for x in range(10)] numbersInTuple = (x for x in range(10)) print(numbersInTuple) print(numbersInList)
结果是这样的:
<generator object <genexpr> at 0x0000025227369510>
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
为什么不能生成Tuple?
tuple是固定不变的,一旦变成tuple,tuple中的每一个元素都不可被改变
numbersInList = [x for x in range(10)] numbersInTuple = tuple(numbersInList)
Python3 入门教程(新版)
154161 学习 · 1075 问题
相似问题