1. int 类型转换 a = "123" b = int(a) b = b+10 print(type(a),a) print(type(b),b) 2. int(num,base=2), base不写的时候默认为10 a = "0011" b = int(a,base=2) print(b) 答案为 3. 3. -.bit_length() 当前数字为2进制时,至少要用多少位来表示 a = 8 b = a.bit_length() print(b) answer…
参考 https://docs.python.org/3/library/functions.html?highlight=int#int If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in radix base 问题:想将input()中返回的字符串转换为int,故尝试用int(),转换…
Python之str()与repr()的区别 str()一般是将数值转成字符串,主要面向用户. repr()是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思.如list,dict使用str()是无效的,但使用repr可以,这是为了看它们都有哪些值,为了显示之用,主要面向python. 官方文档: The str() function is meant to return representations of values which are fairlyhuman-…