num =[3,5,9,0,1,9,0,3]print(num[::-1])#也可以
num.reverse()print(num)
二维列表
构建二维列表,利用循环进行加入
name =['Niumei','YOLO','Niu Ke Le','Mona']
foods =['pizza','fish','potato','beef']
num =[3,6,0,3]
friends =[[],[],[]]for i inrange(len(name)):
friends[0].append(name[i])
friends[1].append(foods[i])
friends[2].append(num[i])print(friends)
由于列表本身也可以作为元素加入列表的,所以并不需要刻意去构建一个二维列表
name =['Niumei','YOLO','Niu Ke Le','Mona']
foods =['pizza','fish','potato','beef']
num =[3,6,0,3]
friends =[]
friends.append(name)
friends.append(foods)
friends.append(num)print(friends)
数字转化
num =input()
result =[]for i inrange(4):
temp = num[i]
a =(int(temp)+3)%9
result.append(str(a))print(int(result[2]),int(result[3]),int(result[0]),int(result[1]),sep='')