学习笔记1-Python二维数组的操作

假设有一数组 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): 30行数组: ['1', '2', '3']1行数组: ['4', '5', '6']2行数组: ['7', '8', '9']
1 2 3 4 5 6 7 8 9 

你可能感兴趣的:(python)