上一页 1 ··· 30 31 32 33 34
摘要: mystr = 'hello world and gzy and java and python' # startswith/endswith(子串。开始位置,结束位置) print(mystr.startswith('hello')) #True print(mystr.startswith('h 阅读全文
posted @ 2021-03-08 15:34 code-G 阅读(115) 评论(0) 推荐(0) 编辑
摘要: mystr = 'hello' # ljust(长度,填充符) 左对齐,多于长度填充字符 长度小于字符串长度原样输出 str1 = mystr.ljust(10, '.') print(str1) # 右对齐 str2 = mystr.rjust(10, '.') print(str2) # 居中 阅读全文
posted @ 2021-03-08 15:32 code-G 阅读(124) 评论(0) 推荐(0) 编辑
摘要: mystr = ' hello world and gzy and java and python ' # 删除左侧空白字符 str1 = mystr.lstrip() print(str1) # 删除右侧空白字符 str2 = mystr.rstrip() print(str2) # 删除两侧空白 阅读全文
posted @ 2021-03-08 15:30 code-G 阅读(143) 评论(0) 推荐(0) 编辑
摘要: mystr = 'hello world and gzy and java and python' # 字符串第一个字符大写 str1 = mystr.capitalize() print(str1) # 字符串中每个单词第一个字符大写 str2 = mystr.title() print(str2 阅读全文
posted @ 2021-03-08 15:28 code-G 阅读(88) 评论(0) 推荐(0) 编辑
摘要: mystr = 'hello world and gzy and java and python' # replace 返回一个新对象,原字符串不变,字符串为不可变类型 str1 = mystr.replace('and', 'he') str2 = mystr.replace('and', 'he 阅读全文
posted @ 2021-03-08 15:26 code-G 阅读(139) 评论(0) 推荐(0) 编辑
摘要: mystr = 'hello world and chris and java and python' #find(子串,开始位置,结束位置) 找不到返回-1 print(mystr.find('and')) print(mystr.find('and',15)) print(mystr.find( 阅读全文
posted @ 2021-03-08 15:20 code-G 阅读(509) 评论(0) 推荐(0) 编辑
摘要: 字符串的切片 阅读全文
posted @ 2021-03-08 15:12 code-G 阅读(477) 评论(0) 推荐(0) 编辑
上一页 1 ··· 30 31 32 33 34