请给出以下代码:
array = [[0, 2], [3, 4]]
for i in array:
print '%d' % i[0][0]
我得到了错误:TypeError: 'int' object has no attribute '__getitem__'
但是如果我换成print'%d' %i
我得到错误:TypeError: %d format: a number is required, not list
如何循环遍历数组并打印每个子数组的第一个和第二个值?你知道吗
谢谢
Tags:
或者更好:
i
是一维的。因此:另外,还不清楚你想要的结果是什么。此解决方案将打印每个列表的第一个元素。你知道吗
你想要
print '%d %d' % (i[0], i[1])
相关问题 更多 >
编程相关推荐