2022年12月10日

摘要: 用法 newstr = string.replace(old,new,max) 参数 old: 被替换的元素 new: 替代old的新元素 max: 可选,代表替换几个,默认全部替换全部匹配的old元素 #定义超长字符串 info = ('对国家的科技等客观角度的恐惧的感觉开关机' '而国家偶尔哦减 阅读全文
posted @ 2022-12-10 22:39 bobo2404 阅读(225) 评论(0) 推荐(0) 编辑
 
摘要: strip将去掉字符串左右两边的指定元素,默认是去掉空格 newstr = string.strip(item) 参数:括弧里需要传一个你想去掉的元素,可不填写 ' hello xiaomu '.strip() //hello xiaomu 'hello xiaomu'.strip('h') //e 阅读全文
posted @ 2022-12-10 21:46 bobo2404 阅读(43) 评论(0) 推荐(0) 编辑
 
摘要: string.find(item) -> item:想查询的元素,返回一个整型 string.index(item) 返回一个整型或者报错 find与index的区别 如果find找不到,会返回-1 如果index找不到元素,会导致程序报错 info = 'python is a good code 阅读全文
posted @ 2022-12-10 20:57 bobo2404 阅读(60) 评论(0) 推荐(0) 编辑