此次文章总结内容为字符串的大小写转换、字符串检查、去掉空格操作。
1. 大小写转换
code |
return |
string.capitalise() |
字符串第一个字符大写 |
>>> name='max'
>>> name.capitalize()
'Max'
>>> name='mAX'
>>> name.capitalize()
'Max'
code |
return |
string.title() |
字符串标题化 |
用法和string.capitalize()
一样
>>> name='max'
>>> name.title()
'Max'
>>> name='MaX'
>>> name.title()
'Max'
code |
return |
string.lower() |
字符串全部转化为小写 |
>>> word1='4beAUtiFUl'
>>> word1.lower()
'4beautiful'
>>> 'BEAUTIFUL123'.lower()
'beautiful123'
code |
return |
string.upper() |
字符串全部转化为大写 |
>>> name='abcdefg'
>>> name.upper()
'ABCDEFG'
>>> 'hiGLKksdf