mystr = 'hello world and itcast and itehima and Python'
1.capitalize() 字符串首字母大写 Hello world and itcast and itehima and python
new_str = mystr.capitalize()
print(new_str)
2.title(): 字符串每个单词首字母大写 Hello World And Itcast And Itehima And Python
new_str1 = mystr.title()
print(new_str1)
3.upper() : 小写转成大写 # HELLO WORLD AND ITCAST AND ITEHIMA AND PYTHON
new_str2 = mystr.upper()
print(new_str2)
4. lover() 大写转小写 hello world and itcast and itehima and python
new_str3 = mystr.lower()
print(new_str3)
删除空格 空白
- lstrip() 删除字符串左侧空白字符(l --left )
- rstrip() 删除字符串右侧的空白字符 (r --right)
- strip() 删除字符串两侧空白字符
字符串对齐操作--
- ljust() 让字符串左对齐
- rjust() 字符串右对齐
- center() 中间对齐(如果是奇数,左侧会少一个字符
字符串序列.ljust(长度,填充字符)
mystr = 'hello world'
mystr.ljust(20,'.')
hello world......
----若字符串长度不够的时候,用''内的内容填充