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

posted @ 2020-11-27 23:45  模糊计算士  阅读(1056)  评论(0编辑  收藏  举报