Python 改变列表排列顺序 sort() + sorted() + reverse() 列表元素都为小写情况
name = ['sd','ad','lbj','kd']
print(name)
print(sorted(name))
print(sorted(name,reverse = True))
print(name)
>>['sd', 'ad', 'lbj', 'kd']
>>['ad', 'kd', 'lbj', 'sd']
>>['sd', 'lbj', 'kd', 'ad']
>>['sd', 'ad', 'lbj', 'kd']
name = ['sd','ad','lbj','kd']
print(name)
name.sort()
name.sort(reverse = True)
print(name)
>>['sd', 'ad', 'lbj', 'kd']
>>['sd', 'lbj', 'kd', 'ad']
name = ['sd','ad','lbj','kd']
print(name)
name.reverse()
print(name)
>>['sd', 'ad', 'lbj', 'kd']
>>['kd', 'lbj', 'ad', 'sd']
JfLam
发布了3 篇原创文章 · 获赞 1 · 访问量 20
私信
关注