python中sort用法

 时间:2024-10-13 07:20:47

1、sort是用来排序列表的。a=[3,1,2]a.sort()print(a)给出列表a的元素排序,默认的是从小到大排列。

python中sort用法

2、a.sort(reverse=True)则是反向排序,从大到小排列。

python中sort用法

3、字母之间也存在先后顺序:a=['a','c','b']a.sort()

python中sort用法

4、大写字母排在小写字母前面:a=['a','A','b','B','c','C']

python中sort用法

5、数亨蚂擤缚字变成的字符串,排在大写字母前面:a=['1','12','123&#泌驾台佐39;, 'a','A','b', 'B','c','C']

python中sort用法

6、英文的标点符号,排在数字型字符串前面:a=[',','.','aBC', '1',&#泌驾台佐39;12','123', 'a','A','b', 'B','c','C']

python中sort用法

7、中文的标点符号,排在英文字母后面,而且句号排在逗号前面:a=[',','.',',','。', '1','12','123', 'a','A','b', 'B','c','C']

python中sort用法

8、列表里面如果即有数字(非字符串形式的数字),又有字符串,则无法排序。原因是:'<' not supported between instances of 'int' and 'str';无法比较数字和字符串的大小。

python中sort用法
  • python输出怎么换行
  • python创建列表
  • python删除重复元素
  • python 字符串转列表
  • python每行输出5个数据
  • 热门搜索
    迟志强歌曲大全 凉鞋磨脚怎么办 呼叫限制怎么取消 明朝皇帝列表及简介 吉利帝豪gs怎么样 怀表怎么带 粽子馅料大全 怎么贴双眼皮贴 泰山特曲价格表大全 娇韵诗怎么样