Python学习【day02】-int类型方法记录
1 #!/usr/bin/env python 2 # -*- coding:utf8 -*- 3 4 #测试并记录int数据类型的各个方法 5 6 num1 = 123 7 #int类型转为二进制后的位数 8 v1 = num1.bit_length() 9 print(v1) 10 11 num2 = "456" 12 print(type(num2)) 13 """ 14 若num2带有其他字符则转化错误 15 Traceback (most recent call last): 16 File "D:/Python_Study/day02/int.py", line 14, in <module> 17 v2 = int(num2) 18 ValueError: invalid literal for int() with base 10: '456a' 19 """ 20 #将str类型转化为int类型 21 v2 = int(num2) 22 print(type(v2), v2)