我有以下代码,工作正常.但是,当我在语句打印中删除注释时,list(B)它会失败并返回为空列表.我想也许X正在获取list(B)作为print语句的一部分执行的地址位置.
import itertools
A = [1,2,3]
B = itertools.product(A,repeat=2)
print str(B)
#print list(B)
X = list(B)
print X
<itertools.product object at 0x7f5ac40a9a50>
[(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)]
Command took 0.03s
Run Code Online (Sandbox Code Playgroud) python ×1