上一页 1 ··· 316 317 318 319 320 321 322 323 324 ··· 367 下一页
摘要: 1、 >>> a = " good " ## 测试字符串,左右都有空格 >>> a ' good ' >>> len(a) 10 >>> a.lstrip() ## 删除左侧空格 'good ' >>> a.rstrip() ## 删除右侧空格 ' good' >>> a.strip() ## 删除 阅读全文
posted @ 2021-02-25 12:29 小鲨鱼2018 阅读(2141) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = "good" >>> a.ljust(1) 'good' >>> a.ljust(10) ## 左对齐 'good ' >>> a.ljust(10,"-") ## 左对齐,以-填充多余宽度 'good ' >>> a.ljust(20,"x") 'goodxxxxxxxxxx 阅读全文
posted @ 2021-02-25 12:22 小鲨鱼2018 阅读(1266) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = "gooood" >>> a.replace("o","x") ## 将o全部替换为x 'gxxxxd' >>> a.replace("o","x",1) ## 指定替换次数 'gxoood' >>> a.replace("o","x",2) 'gxxood' >>> a.re 阅读全文
posted @ 2021-02-25 12:16 小鲨鱼2018 阅读(3087) 评论(0) 推荐(0) 编辑
摘要: 1、拆分字符串 >>> a = "2018:03:15" >>> a '2018:03:15' >>> a.split(sep = ":") ## sep指定拆分的分隔符 ['2018', '03', '15'] >>> a = "ab:c:aaa:d:ee:fddf:dfd:34:2:89:887 阅读全文
posted @ 2021-02-25 10:32 小鲨鱼2018 阅读(477) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = "good" >>> a 'good' >>> a.find("g") ## 如果查找字符存在,则返回第一个索引 0 >>> a.find("o") 1 >>> a.find("d") 3 >>> a.find("x") ## 如果不存在,则返回-1 -1 >>> a.find 阅读全文
posted @ 2021-02-25 10:01 小鲨鱼2018 阅读(1044) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = "g\to\to\tg" >>> a 'g\to\to\tg' >>> a.expandtabs() 'g o o g' >>> 阅读全文
posted @ 2021-02-25 09:52 小鲨鱼2018 阅读(669) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = "good" >>> a 'good' >>> a.startswith("g") ## 判断字符串是否以g开头 True >>> a.startswith("o") ## 判断是否以o开头 False >>> a.startswith("d") False >>> a.end 阅读全文
posted @ 2021-02-25 09:48 小鲨鱼2018 阅读(1450) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = "good" >>> a 'good' >>> a.count("g") ## 统计"g"出现的次数 1 >>> a.count("o") ## 统计"o"出现的次数 2 >>> a.count("d") ## 统计d出现的次数 1 >>> a.count("go") ## 统 阅读全文
posted @ 2021-02-25 09:36 小鲨鱼2018 阅读(13054) 评论(0) 推荐(0) 编辑
摘要: >>> a = "good" ##测试字符串 >>> a 'good' >>> type(a) <class 'str'> >>> a.center(1) ## 指定宽度1 'good' >>> a.center(10) ## 指定宽度10,默认使用空格填充 ' good ' >>> a.cente 阅读全文
posted @ 2021-02-25 09:16 小鲨鱼2018 阅读(1444) 评论(0) 推荐(0) 编辑
摘要: 1、 >>> a = "gooD" ##测试字符串 >>> a.lower() ##全部变为小写 'good' >>> a.upper() ## 全部变为大写 'GOOD' >>> a.casefold() ## 全部变为小写 'good' >>> a.capitalize() ## 首字母大写 ' 阅读全文
posted @ 2021-02-25 09:07 小鲨鱼2018 阅读(442) 评论(0) 推荐(0) 编辑
上一页 1 ··· 316 317 318 319 320 321 322 323 324 ··· 367 下一页