假设有一数组 A = [‘1’,‘2’,‘3’,‘4’]
A = ['1', '2', '3', '4']
B = A * 4
print("一维数组乘数字的效果:", B)
运行结果如下:
一维数组乘数字的效果: ['1', '2', '3', '4', '1', '2', '3', '4', '1', '2', '3', '4', '1', '2', '3', '4']
假设有二维数组C = [[‘1’, ‘2’, ‘3’], [‘4’, ‘5’, ‘6’], [‘7’, ‘8’, ‘9’]]
C = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
print("数组C[2][1]:", C[2][1])
print("数组C的长度len(C):", len(C))
# 打印数组C的每一行
for i in range(len(C)):
print("第%d行数组:" % i, C[i])
# 打印数组C的每一个元素
for i in range(len(C)):
for j in range(len(C[i])):
print(C[i][j], end=" ")
运行结果如下:
数组C[2][1]: 8
数组C的长度len(C): 3
第0行数组: ['1', '2', '3']
第1行数组: ['4', '5', '6']
第2行数组: ['7', '8', '9']
1 2 3 4 5 6 7 8 9