python培训之字符串中有哪些方法

发布时间:2023-03-01 09:41:57 人气:24 作者:多测师

  python字符串中有哪些方法

  字符串方法

  1.capitalize() :将字符串的第一个字符转换为大写字母

  2.title():将所有单词的第一个字符转换为大写字母

  3.upper():将字符串的所有字符转化为大写字母

  4.lower():将字符串的所有字符转化为小写字母

  5.swapcase() :将字符串的所有字符大小写互换

python培训之字符串中有哪些方法

  实例

  >>> string = 'while There is life There is hope.'

  >>> string.capitalize()

  # 'While there is life there is hope.'

  >>> string.title()

  # 'While There Is Life There Is Hope.'

  >>> string.upper()

  # 'WHILE THERE IS LIFE THERE IS HOPE.'

  >>> string.lower()

  # 'while there is life there is hope.'

  >>> string.swapcase()

  # 'WHILE tHERE IS LIFE tHERE IS HOPE.'

  以上就是python字符串方法的介绍,希望对大家有所帮助。更多Python学习指路:请关注多测师。https://www.e70w.com/xwzx/


返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线