Files
2025PY/day20/07-字符串的方法.py
2025-05-22 16:50:44 +08:00

47 lines
586 B
Python

# 1、str.replace(old,new,count) 返回str副本 old->new 替换count次数 count可以省略
str='hello,zhangsan,lisi,wangwu,lisi,hello,zhangsan'
print(str.replace('hello',''))
print(str.replace('hello','',1))
print(str.replace('hello',' '))
# 2、str.center(width,fillchar) 字符串居中函数 第二个参数为宽度不足填充符号可以省略
str='hello'
print(str.center(10,'*'))
print(str.center(21,'#'))
# 三角形
str=''
for i in range(1,10,2):
print(str.center(i,'*'))