数字和字符串内置模块功能用法介绍
# a = "132" # b = int(a) #将字符串转化成数字 # a = "123" # print(type(a),a) # 查看数据类型并打印 # num = '010101' # v = int(num,base=2) # print(v) # 将num中的字符串用十六进制转换成十进制 # # age = 10 # r = age.bit_length() # print(r) # 当前数字的二进制用几位表示 # test = "zhongguo" # v = test.capitalize() # print(v) # 将字符串中的首字母大写 # test = "ZHONGGUO" # v1 = test.casefold() # print(v1) # v2 = test.lower() # print(v2) # 这两个命令都是把大写字母变成小写字母 # casefold更牛逼,很多未知的对应变小写 # v = "zhongguo" # a = v.center(20,"&") # print(a) # 填充20个空白把字符串zhongguo放中间 # 也可以在括号里添加其他东西 # test = "zhongguoxucheng" # v = test.count('xu',5,7) # print(v) # 查找test字符串中含有几个'xu'字符串 # 5代表从第几个字符开始,7代表从第7个字符结束 # test = "alex" # v = test.endswith('x') # print(v) # 字符串中是否以x结尾 # test = "alex" # v = test.startswith('ex') # print(v) # 字符串中是否以ex开头 # test = "alexalex" # v = test.find('ex',5,8) # print(v) # 从开始往后找需要找的字符位置'ex'找到后停止。起始位置从0开始 # 5代表从5开始 8代表从8结束 # # test = 'i am {name},age {a}' # print(test) # v = test.format(name='alex',a=9) # print(v) # 格式化将一个字符串中的占位符替换为指定的值。 # test = 'i am {name},age {a}' # v = test.format_map({'name':'alex','a':19}) # print(v) # test = "dfadfd3432432" # v = test.isalnum() # print(v) # 判断字符串中是否只包含字母和数字