04-Integral类型数据

Integral类型:
1,整型(不可变类型)int
    123456,93524359324,
    转换方法:int()
 
可用类
-计算一个整数转换为二进制后所需的最小位数
.bit_length()
a = 1
print(a.bit_length())
b = 8
print(b.bit_length())
c = 128
print(c.bit_length())
输出结果:
1
4
8

 

 
-转换为字节类型,用指定位数的字节来表示
.to_bytes(位长n, byteorder='big|little')
a = 15
v1 = a.to_bytes(2, byteorder='big')
v2 = a.to_bytes(2, byteorder='little')
v3 = a.to_bytes(10, byteorder='big')
v4 = a.to_bytes(10, byteorder='little')
print(v1)
print(v2)
print(v3)
print(v4)
运行结果:
b'\x00\x0f'
b'\x0f\x00'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f'
b'\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00'

[ps:\x开头则表示是十六进制]

 
 
2,布尔型bool
    True,False
    转换方法:bool()
一般0和空值都为False

转载于:https://www.cnblogs.com/xiaofeiweb/p/6848565.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值