python第二课,字符串的魔法
作者:互联网
基本数据类型:
数字 int ,所有功能,都放在int 里
a1 = 123
转化字符串为数字
1 a = "123" 2 print(type(a),a) 3 b = int(a) 4 print(b)
1 age = 5 2 r = age.bit_length() 3 print(r)
字符串 str
s1 = "addfafd"
s2 = "erwer"
列表 list
元组 tuple
字典 duct
布尔值 bool
1 # # 首字母大写 2 # test = "luofei" 3 # v = test.capitalize() 4 # print(v) 5 6 # 所有都变小写,casefold更强大,很多未知的对应变小写 7 # name = "luOFei" 8 # v1 = name.lower() 9 # print(v1) 10 # v2 = name.casefold() 11 # print(v2) 12 13 14 # 设置宽度,并将内容居中 15 # 20指总长度 16 # *空白填充,一个字符,可有可无 17 # name = "LF" 18 # v = name.center(20,"*") 19 # print(v) 20 21 # 计算字符出现个数,参数是范围长度可有是两个参数,分别是开始和结尾 22 # name = "luofeilfengyandedianh" 23 # v = name.count("l",10) 24 # print(v) 25 26 27 # 判断以什么结尾\开始 28 # name = "luofeiluo" 29 # v = name.endswith("uo") 30 # v1 = name.startswith("f") 31 # print(v) 32 # print(v1) 33 34 # name = "luofe\ti" 35 # print(name) 36 # v = name.expandtabs(2) 37 # print(name,len(v)) 38 39 # 从开始往后找,找到第一个之后,获取其位置 40 # # > 或>= 41 # name = "luofeilfdengyan" 42 # v = name.find("den",2,15) 43 # print(v) 44 45 # index,找不到报错。 46 # name = "luofeilfdengyan" 47 # v = name.index("fdg") 48 # print(v) 49 50 51 # 判断字符串中是否只包含 字母和数字 52 # test = "234ee_+" 53 # v = test.isalnum() 54 # print(v)
标签:20,第二课,v1,python,魔法,test,int,print,name 来源: https://www.cnblogs.com/lfluofei/p/15853447.html