int文档
文档
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | class int ( object ): """ int(x=0) -> integer int(x, base=10) -> integer ---------------------------------------------------------------------------------- Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero. 将一个数字或者字符串(str.isNum==True),如果没有给参数,默认为0(如print(int())结果为0) 如果参数x是一个数字,则返回x.__int__()的结果,如果是一个浮点数,则会只取整数, (如print(int(2.5))的结果为2) ---------------------------------------------------------------------------------- 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 the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int('0b100', base=0) 4 base参数为进制,默认为10进制 """ def bit_length( self ): # real signature unknown; restored from __doc__ """ int.bit_length() -> int ---------------------------------------------------------------------------------- 返回一个int数转换为二进制后至少要用多少位来表示,返回值为int类型 Number of bits necessary to represent self in binary. 数字必须转换为二进制后再计算 ---------------------------------------------------------------------------------- >>> bin(37) '0b100101' >>> (37).bit_length() 6 如:37的二进制为'0b100101'(6位),那么37的bit_length()结果为6 ---------------------------------------------------------------------------------- """ return 0 |
示例
1 2 3 4 5 6 7 8 9 | print ( int ()) # 结果为0 print ( int ( 2.5 )) # 结果为 n = 250 n_bytes = bin (n) print (n_bytes) # 结果为0b11111010 print (n.bit_length()) # 结果为8 print ( int ( '0b1010' ,base = 0 )) # 结果为10 |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步