使用print(i, j)
和print(i)
的两个设置返回相同的结果。有这样的情况吗
应该在另一个上面使用还是可以互换使用?
desc = {'city': 'Monowi', 'state': 'Nebraska', 'county':'Boyd', 'pop': 1}
for i, j in desc.items():
print(i, j)
for i in desc.items():
print(i)
for i, j in desc.items():
print(i, j)[1]
for i in desc.items():
print(i)[1]
如果删除打印中的括号,则两者都不同,因为您使用的是python 2X
输出
items()
返回一个视图对象,该对象允许您迭代(key, value)
元组。所以基本上你可以像处理元组那样操作它们。document可能有助于:另外,我认为
print(i, j)[1]
在Python 3中会导致错误,因为print(i, j)
返回None
。相关问题 更多 >
编程相关推荐