整形常带功能
1.int
将其他数据类型变成整型,如字符串
1 a = "123" 2 v = int(a) 3 print v
1 num = "b" 2 v = int(num, base=16) # base是指将数字转为16进制 3 print(v)
2.bit_length:显示整数转为二进制时的长度
1 bit_length(...) 2 int.bit_length() -> int 3 4 Number of bits necessary to represent self in binary. 5 >>> bin(37) 6 '0b100101' 7 >>> (37).bit_length() 8 6
1 age = 5 2 r = age.bit_length() 3 print(r)
1 >>> 3