>>>setup.replace('duck','marmoset')'a marmoset goes into a bar...'#修改最多100处>>>setup.repalce('a ','a famous',100)'a famous duck goes into a famous bar...'
不常用字符串函数(大小写与对齐方式)
>>>setup ='a duck goes into a bar...'#将字符串收尾的.都删除>>>setup.strip('.')'a duck goes into a bar'#让字符串首字母变成大写>>>setup.capitalize()'A duck goes into a bar...'#让所有单词开头字母都变成大写>>>setup.title()'A Duck Goes Into A Bar...'#让所有字母都转换为大写>>>setup.upper()'A DUCK GOES INTO A BAR...'#将所有字母转换为小写>>>setup.lower()'a duck goes into a bar...'#将所有字母的大小写转换>>>setup.swapcase()'a DUCK GOES INTO A BAR...'#假设setup字符串被排版在指定长度(这里是30个字符)的空间里#在30个字符位居中>>>setup.center(30)' a duck goes into a bar... '#左对齐>>>setup.ljust(30)'a duck goes into a bar... '#右对齐>>>setup.rjust(30)' a duck goes into a bar...'