str = 'hello world and hello python and hello java'
1、capitalize() ---字符串首字母大写
new_str = str.capitalize()
print(new_str)
执行结果:Hello world and hello python and hello java
2、title() ---字符串中每个单词首字母大写
new_str = str.title()
print(new_str)
执行结果:Hello World And Hello Python And Hello Java
3、upper() ---小写转大写
new_str = str.upper()
print(new_str)
执行结果:HELLO WORLD AND HELLO PYTHON AND HELLO JAVA
4、lower() ---大写转小写
new_str = str.lower()
print(new_str)
执行结果:hello world and hello python and hello java
删除字符串空白字符
1、lstrip() ---删除字符串左侧的空白字符
2、rstrip() ---删除字符串右侧的空白字符
3、strip() ---删除字符串两侧的空白字符
字符串对齐
语法:字符串序列.函数(长度,填充字符)
1、ljust() ---左对齐
2、rjust() ---右对齐
3、center() ---居中对齐
判断字符串开头结尾
语法:字符串序列.函数(子串,开始位置下标,结束位置下标)
1、startswith() ---判断字符串是否以某个字段开头
2、endswith() ---判断字符串是否以某个字段结尾
判断字符串
1、isalpha() ---判断字符串中都是字母
2、isdigit() ---判断字符串中都是数字
3、isalnum() ---判断字符串中都是数字或者字母
4、isspace() ---判断字符串中都是空白