摘要: .strip().split()name='*egon**'print(name.strip()) #默认去掉空格print(name.strip('*')) #去掉指定字符print(name.lstrip('*')) #从左开始去掉指定字符print(name.rstrip('*')) #从右开 阅读全文
posted @ 2020-05-03 10:00 huangjunlong 阅读(1367) 评论(0) 推荐(0)
摘要: .replace() .join() .format() name='alex say :i have one tesla,my name is alex'print(name.replace('alex','SB',1)) #字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串tag 阅读全文
posted @ 2020-05-03 09:42 huangjunlong 阅读(75) 评论(0) 推荐(0)
摘要: .startswith() .endswith() isdigit() name='alex_SB'print(name.endswith('SB')) #判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False,可选参数"start"与"end"为检索字符串的开始与结束位置 阅读全文
posted @ 2020-05-03 09:23 huangjunlong 阅读(408) 评论(0) 推荐(0)
摘要: .find() .index() .rfind() .count() s='hello world'print(s.find('a')) # 查找指定字符串,找不到返回-1print(s.find('l',3,4)) # 需输入开始查找的索引和结束的索引,找到显示索引,找不到则返回-1,不会报错pr 阅读全文
posted @ 2020-05-02 19:41 huangjunlong 阅读(134) 评论(0) 推荐(0)
摘要: .ljust(width) .rjust(width) .center(width) .zfill(width) a='1 3 4' print(a.ljust(10)) # 获取固定长度,左对齐,右边不够用空格补齐 print(a.rjust(10)) # 获取固定长度,右对齐,左边不够用空格补齐 阅读全文
posted @ 2020-05-02 19:22 huangjunlong 阅读(89) 评论(0) 推荐(0)
摘要: .upper() .lower() .swapcase() .capitalize() .title() a='fheGifHF'print(a.upper()) # 全部大写print(a.lower()) # 全部小写print(a.swapcase()) # 大小写互换print(a.capi 阅读全文
posted @ 2020-05-02 19:10 huangjunlong 阅读(122) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示