python基本数据类型之整型
整形常带功能
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
每天学习新的知识,会让自己更加充实