s='abcdsh'
# 把字符串都转为大写 ,会产生一个新的字符串对象
print(s.upper(),id(s),id(s.upper()))
# 把字符串都转为小写,会产生一个新的字符串对象
b = 'hello,Python'
print(b.lower(),id(b),id(b.lower()))
# 大转小 小转大
f = 'hfhhHGSDG'
print(f.swapcase(),id(f),id(f.swapcase()))
#每个字母开头变为大写 其余变为小写
print(b.title())
ABCDSH 1875249815992 1875249850552
hello,python 1875250826480 1875253086128
HFHHhgsdg 1875253086064 1875253086128
Hello,Python
s='hello,Python'
# 居中对齐 字符串总宽度,填重复
print(s.center(20,'*'))
# 左对齐
print(s.ljust(20,'*'))
#右对齐
print(s.rjust(20,'*'))
#补0
print('-2137'.zfill(10))
****hello,Python****
hello,Python********
********hello,Python
-000002137
#字符串分割
s = 'hello world python'
print(s.split())
# 从左侧开始分割
s1 = 'hello|world|python'
print(s1.split(sep='|'))
print(s1.split(sep='|',maxsplit=1))
# 从右侧开始分割
print(s1.rsplit(sep='|'))
print(s1.rsplit(sep='|',maxsplit=1))
['hello', 'world', 'python']
['hello', 'world', 'python']
['hello', 'world|python']
['hello', 'world', 'python']
['hello|world', 'python']