• Python字符串字母大小写变换


    说明:

    字符串就是一系列字符,在Python中用引号括起来的都是字符串,引号可以是单引号,也可以是双引号,比如:“This is a book.”  ‘This is an apple.’

    接下来简单说明下关于字符串大小写的变换。

    操作:

    casefold() 所有字母小写
    lower() 所有字母小写
    upper() 所有字母大写
    capitalize() 所有字母小写
    title() 所有首字母大写,其余字母小写
    swapcase() 大小写字母替换
    这几个方法都是生成新的字符串,不对原字符串内容进行修改。
    demo = 'tHis iS a GOod boOK.'
    print(demo.casefold())
    print(demo.lower())
    print(demo.upper())
    print(demo.capitalize())
    print(demo.title())
    print(demo.swapcase())
    

      

    输出:

    this is a good book.
    this is a good book.
    THIS IS A GOOD BOOK.
    This is a good book.
    This Is A Good Book.
    ThIS Is A goOD BOok.
    

      

  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    C++生产和使用的临时对象
    RecyclerView0基于使用
    Docker创建MySQL集装箱
  • 原文地址:https://www.cnblogs.com/mengjinxiang/p/12368482.html
Copyright © 2020-2023  润新知