美文网首页
2020-12-19 sort() sorted()

2020-12-19 sort() sorted()

作者: Python_Camp | 来源:发表于2020-12-19 18:01 被阅读0次

    字符串的降序

    输入:数字或字符串
    输出:降序后的数字

    How to convert and sort?

    step1: str()
    step2:sorted()
    step3:''.join()
    step4: int()

    def descending_order(num):
        return int(''.join(sorted(str(num),reverse=True)))
    num = 123456789
    #num = '123456789'
    print(descending_order(num))
    
    num = ['9', '8', '7', '6', '5', '4', '3', '2', '1']
    print(max(num),min(num))
    

    相关文章

      网友评论

          本文标题:2020-12-19 sort() sorted()

          本文链接:https://www.haomeiwen.com/subject/fpycnktx.html