整型:
type():显示数据类型
# 整型,int
# python3里,不管数字有多大,都是int类型
# python2里,有大小区分,长整型:long int
a = ""
print(type(a),a) b = int (a)
print(type(b),b)
#进制转换
num = "d"
v = int (num, base=16)
print(v)
#当前数字用二进制的位数表示
age = 4
r = age.bit_length()
print(r)
字符型:
#索引
test = "alexalex"
v = test.find("xa")
print(v)
占位符
test = 'i am {0},age {1}'
v = test.format('alex',12)
print(v)
test.format_map({"name":'alex',"a":19})
#字符串中是否只包含字母和数字
test = "abc123"
v = test.isalnum()
print(v)
#制表符
s = "username\temail\tpassword\nzhangsan\tzhang@qq.com\t123\nzhangsan\tzhang@qq.com\t123\nzhangsan\tzhang@qq.com\t123"
v = s.expandtabs(20)
print(v)
#判断是否为字母,汉字
test = "jing"
v = test.isalpha()
print(v)
#判断字符串是否为数字
test = "Ⅱ"
v1 = test.isdecimal() #支持123
v2 = test.isdigit() #支持②,123
v3 = test.isnumeric() #支持 三,②,Ⅱ,123
print(v1,v2,v3)
#字母,数字,下划线:标识符
#判断是否为标识符
test = "_jfgh"
v = test.isidentifier()
print(v)
#判断是否存在不可显示的字符
#\t 制表符
#\n 换行符
test = "you are"
v = test.isprintable()
print(v)
#判断是否全部是空格
test = " "
v = test.isspace()
print(v)
test = "you are a man"
v1 = test.title() #转换为标题
print(v1)
v2 = v1.istitle() #判断是否为标题
print(v2)
# 将字符串中的每个元素按照指定分隔符进行拼接
test = "清风明月两岸绿"
print(test) #清风明月两岸绿
t = ' '
v = t.join(test) #清 风 明 月 两 岸 绿
print(v)
#填充
test = 'alex'
v1 = test.ljust(10,"@") #alex@@@@@@
v2 = test.rjust(10,"@") #@@@@@@alex
print(v1,v2)
#判断是否全部为大小写 和 转换为大小写
test = "Alext"
v1 = test.isupper()
v2 = test.upper()
print(v1,v2) v3 = test.islower()
v4 = test.lower()
print(v3,v4)
#去除左右空格,换行
test = "allell"
v1 = test.lstrip()
v2 = test.rstrip()
v3 = test.strip() #从指定的字符串中去除原文中左右子序列
#指定字符中有几个字符就在原文中找几个字符
x1 = test.lstrip("ex")
x2 = test.rstrip("fl")
x3 = test.strip("ax")
print(x2)
#替换对应关系
test1 = "abcd"
test2 = ""
v = "fbgyuewt;dkfobgdsc"
m = str.maketrans(test1,test2)
new_v = v.translate(m) # f2gyuewt;4kfo2g4s3
print(new_v)
test = "testghsjghfsf"
#分成三份
v1 = test.partition("s") #('te', 's', 'tghsjghfsf')
v2 = test.rpartition("s")
#遇到指定字符全部分割
v3 = test.split("s")
v4 = test.rsplit("s") #['te', 'tgh', 'jghf', 'f']
print(v1)