Python声明和定义数组

# 一、一维数组
# 直接定义
test1 = [0, 1, 2, 3, 4, 5, 6]
print(test1)

# 间接定义
test2 = [0 for i in range(6)]
print(test2)

# 数组乘法
test3 = [0] * 6
print(test3)

# 二、二维数组
# 直接定义
test11 = [[0, 0], [0, 0], [0, 0]]
print(test11)

# 间接定义
test12 = [[0 for i in range(3)] for i in range(3)]
print(test12)

# 数组乘法
test13 = [[0, 0]] * 3
print(test13)

输出结果:

20201127234429

原文地址:https://www.cnblogs.com/fanlumaster/p/14051038.html