输出列表中的元素大写格式
color = ["red","green","blus","yellow"]
for i in color:
print(i.upper())
将列表中的元素转换为大写格式
color = ["red","green","blus","yellow"]
color = [i.upper() for i in color]//列表推导式
print(color)
生成一个以字母a开头的新列表
fruit = ["apple","banana","pear","orange"]
new_fruit = [i for i in fruit if i.startswith("a")]
print(new_fruit)
输出倒序列表
color = ["red","green","blus","yellow"]
print(color[::-1])
遍历倒序
color = ["red","green","blus","yellow"]
for i in color[::-1]:
print(i)
color = ["red","green","blus","yellow"]
for i in reversed(color):
print(i)
print(color)
遍历排序的序列
color = ["red","green","blus","yellow"]
for i in sorted(color):
print(i)
for i in sorted(color,reverse=True)://反向排序
print(i)