字符串修改
>>> wu
‘wuang‘
>>> wu = wu[:2] + ‘zhang‘
>>> wu
‘wuzhang‘
>>> wu
‘wuzhang‘
直接使用replace修改替换
>>> wu = wu.replace(‘uzh‘,‘u‘)
>>> wu
‘wuang‘
>>> ‘zhangsAn‘.replace(‘A‘,‘a‘)
‘zhangsan‘
替换一次
>>> wu = ‘wuangwuang‘
>>> wu.replace(‘wuang‘,‘WUANG‘,1)
‘WUANGwuang‘
>>> wu.replace(‘wuang‘,‘WUANG‘)
‘WUANGWUANG‘
时间: 2024-12-10 07:46:00