How can i see the content of a list in python after taking input from the user and appending it to the list?
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 | n = int(input()) mat = [] for i in range(n): row = map(int, input().split()) mat.append(row) print(mat) |
当我运行此代码时,会得到以下O/P
[在0x7f30e08ccba8处映射对象,在0x7f30df3a438处映射对象,在0x7f30df3a3518处映射对象]
3.6中的map对象返回迭代器。您需要迭代它的所有值,方法是打印每个项,或者简单地将其包装成一个
1 2 3 4 5 6 7 | n = int(input()) mat = [] for i in range(n): row = list ( map(int, input().split()) ) # iterate all the values immediately mat.append(row) print(mat) |
对于python2.x,
请参见https://docs.python.org/3/library/functions.html_map