售前咨询:400-100-2938
可以使用sorted函数对字符串进行降序排序,然后使用join方法将排好序的字符重新组合成一个字符串。示例如下:
s = "hello world" sorted_s = ''.join(sorted(s, reverse=True)) print(sorted_s)
输出结果为:
wroolldlh e
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python字符串排序规则有哪些