标签:odi 直接 start nbsp case map 包含 index tar
#!/usr/bin/env python # -*- coding:utf-8 -*- name = "郑建文" "郑建文" 是字符串 "郑"是字符 """ # ctrl + ? 快捷键整体注释 if "z正" in name: print(‘OK‘) else: print(‘Error‘) if "才" not in name: print(‘不在‘) else: print(‘在‘) a = ‘文‘ not in name print(a) """ 数字有数字的功能 a = 123 v = a.bit_length() print(v) #字符串有字符串的功能 name1 = "shizhengwen" v1 = name1.upper() print(v1) name2 = "LaiYing" v2 = name2.upper() print(v2) int str a = "123" print(type(a),a) b = int(a) print(type(b),b) num = "0011" v = int(num,base=2) print(v) num = "a" v = int(num,base=16) print(v) age = 3 r = age.bit_length() print(r) #首字母大写 test = "alex" v = test.capitalize() print(v) #所有大写变成小写,casefold更牛逼,很多未知的对应变小写 test = "aLex" v1 = test.casefold() print(v1) v2 = test.lower() print(v2) 设置宽度,将内容居中 20代指总长度 * 代表填充,一个字符,可以为空 v = test.center(20,"*") print(v) 在字符串中寻找包含ex,回馈出总的出现数量 test = "aLexalexr" v = test.count("ex") print(v) test = "aLexalexr" v = test.count("ex",5,10) print(v) 欠 encode decode 判断是否以e结尾 判断是否以al开头 test = "alex" v = test.endswith("e") v1 = test.startswith("al") print(v) print(v1) 欠 test = "12345678\t9" v = test.expandtabs(6) print(v,len(v)) 从前往后找,找到第一个之后,获取该字符的位置 test = "alexalex" 未找到 -1 v = test.find("ex",2,8) print(v) index找不到,会直接报错,忽略 test = "alexalex" v = test.index("exs") print(v) 格式化,将一个字符串中的占位符替换为指定的值 test = ‘i am {name},age{num}‘ v = test.format(name=‘alex‘,num=19) print(v) test = ‘i am {1},age{1}‘ v = test.format(‘alex‘,19) print(v) 格式化,传入的值{"name":"alex","a":21} test = ‘i am {name},age{a}‘ v1 = test.format(name="ff",a=20) v2 = test.format_map({"name":"alex","a":21}) print(v1) print(v2) 判断字符串中是否只包含字母和数字 test = "aadd123-" v = test.isalnum() print(v)
标签:odi 直接 start nbsp case map 包含 index tar
原文地址:https://www.cnblogs.com/ykblogs/p/12640978.html