随笔分类 - 字符串str
摘要:lst = list("AABCDCBEG") # ['A', 'A', 'B', 'C', 'D', 'C', 'B', 'E', 'G'] # print(lst) st = set(lst) # print(st) # {'D', 'A', 'C', 'G', 'E', 'B'} lst =
阅读全文
摘要:mystr = '\n \tthis is a cat \n \r ' mystr = mystr.strip() # 默认去掉两头的 空格、换行符\n,制表符\t、回车符\r print(mystr) # 只要头尾包含有指定字符序列中的字符就删除 mystr = '1213Hello Word23
阅读全文
摘要:s = str.split("Hello World") # ['Hello', 'World'] s = "Hello World".split() # ['Hello', 'World'] s = str.upper("Hello World") # HELLO WORLD s = str.is
阅读全文
摘要:names = ["Tom Cat", "Jerry Mouse", "Thomas Basper", "Gerald Din"] res = sorted(names, key=len) # 按照名字长度排序 ['Tom Cat', 'Gerald Jin', 'Jerry Mouse', 'Th
阅读全文