美文网首页
python 字符串大小写转换

python 字符串大小写转换

作者: 沧海2122537190 | 来源:发表于2019-12-04 16:38 被阅读0次

    1.将字符串所有字符转为大写

    upper()

    str="StopPed by uSer"
    print(str.upper())
    #结果为 STOPPED BY USER
    

    2.将字符串所有字符转为小写

    lower()

    str="StopPed by uSer"
    print(str.lower())
    #结果为 stopped by user
    

    3.将字符串第一个字母转为大写,其余转成小写

    capitalize()

    str="stopPed by uSer"
    print(str.capitalize())
    #结果为 Stopped by user
    

    4.将字符串每个单词的首字母转为大写,其余为小写

    title()

    str="StopPed by uSer"
    print(str.title())
    #结果为 Stopped By User
    

    相关内容
    istitle() 判断字符串是否是每个单词的首字母转为大写,其余为小写的形式

    str="StopPed by uSer"
    print(str.istitle())
    #结果为 False
    str="Stopped By User"
    print(str.istitle())
    #结果为True
    

    相关文章

      网友评论

          本文标题:python 字符串大小写转换

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