在python中打印返回的内存地址



当我试图打印matrix1时,输出是对象的内存地址。

print("enter n for nxn matrix")
n = int(input())
matrix1 = []
matrix2 = []
#taking elements of first matrix
print("Enter elements of first matrix")
for i in range(0,n):
#taking elements of first column
print("Enter elements of ",i,"column, seperated by space")
#raw_input().split() will split the string
#'1 2 34'.split() will give ['1', '2', '34']
#map will convert its elements into integers [1, 2, 34]
matrix1.append(map(int,input().split()))
print("Matrix 1 is",matrix1)
print(matrix1)

欧普特收到了。

enter n for nxn matrix
2
Enter elements of first matrix
Enter elements of  0 column, seperated by space
2 3
Enter elements of  1 column, seperated by space
4 5
Matrix 1 is [<map object at 0x101834898>, <map object at 0x1032d2f60>]

不确定打印对象的内存地址的原因。我在用蟒蛇。

map返回自身(或者说它返回其类型的对象更好(,但您仍然可以迭代它:

j = [1, 2, 3, 4]
j = map(lambda x: x+1, j)
{x for x in j}

提供:

{2, 3, 4, 5}

最新更新