python整型数据类型符_python学习(二):基本数据类型:整型,字符型

整型:

type():显示数据类型

# 整型,int

# python3里,不管数字有多大,都是int类型

# python2里,有大小区分,长整型:long int

a = "123"

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 = "1234"

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)

标签:alex,v1,python,数据类型,print,v2,v3,整型,test

来源: https://www.cnblogs.com/illion792538535/p/10453733.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值