Python字符串,去空白和大小写切换
作者:互联网
删除空白
Python能够找出字符串开头和末尾多余的空白。要删除空白可用rstrip()(删除末尾空白)、lstrip()(删除开通空白)和strip()(删除两边空白)
favorite_languages = " python "
print("\"" + favorite_languages + "\"")
print("\"" + favorite_languages.rstrip() + "\"")
print("\"" + favorite_languages.lstrip() + "\"")
print("\"" + favorite_languages.strip() + "\"")
字符串大小写切换
title(): 首字母大写
upper(): 全部大写
lower(): 全部小写
name = "Liang chen"
print("小写:" + name.lower())
print("大写:" + name.upper())
print("首字母大写:" + name.title())
标签:name,空白,Python,favorite,大写,languages,print,大小写,字符串 来源: https://blog.csdn.net/a1322958442/article/details/122160546