列表:
[abs(x) for x in vec]#abs将所有负数转换成正数
freshfruit = [' banana', ' loganberry ', 'passion fruit ']
[weapon.strip() for weapon in freshfruit]#strip()去除列表中前后的空格
matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
]
list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
for i in reversed(range(1, 10, 2)):#reversed反向循环
print(i)
9
7
5
3
1