int类的常用方法说明

一、查看int的方法列表 :dir(int)

[‘abs‘, ‘add‘, ‘and‘, ‘bool‘, ‘ceil‘, ‘class‘, ‘delattr‘, ‘dir‘, ‘divmod‘, ‘doc‘, ‘eq‘, ‘float‘, ‘floor‘, ‘floordiv‘, ‘format‘, ‘ge‘, ‘getattribute‘, ‘getnewargs‘, ‘gt‘, ‘hash‘, ‘index‘, ‘init‘, ‘int‘, ‘invert‘, ‘le‘, ‘lshift‘, ‘lt‘, ‘mod‘, ‘mul‘, ‘ne‘, ‘neg‘, ‘new‘, ‘or‘, ‘pos‘, ‘pow‘, ‘radd‘, ‘rand‘, ‘rdivmod‘, ‘reduce‘, ‘reduce_ex‘, ‘repr‘, ‘rfloordiv‘, ‘rlshift‘, ‘rmod‘, ‘rmul‘, ‘ror‘, ‘round‘, ‘rpow‘, ‘rrshift‘, ‘rshift‘, ‘rsub‘, ‘rtruediv‘, ‘rxor‘, ‘setattr‘, ‘sizeof‘, ‘str‘, ‘sub‘, ‘subclasshook‘, ‘truediv‘, ‘trunc‘, ‘xor‘, ‘bit_length’, ‘conjugate’, ‘denominator’, ‘from_bytes’, ‘imag’, ‘numerator’, ‘real’, ‘to_bytes’]

二、查看方法具体说明:help(int)

bit_length(…)

| int.bit_length() -> int |
| Number of bits necessary to represent self in binary.
| >>> bin(37)
| ‘0b100101’
| >>> (37).bit_length()
| 6

代码举例:

i1= 12345;
print(i1.bit_length());
14
i1= 123;
print(i1.bit_length());
7
(100).bit_length();
7

conjugate(…)
Returns self, the complex conjugate of any int
返回自己

(4569113491365).conjugate();
4569113491365
(0b10010).conjugate();
18
i=15;
i.conjugate();
15

* int.from_bytes(bytes, byteorder, , signed=False)**
Return the integer represented by the given array of bytes.
返回字节系列代表的整数

int.from_bytes(b’\x00\x10’, byteorder=’big’)
16
int.from_bytes(b’\x00\x10’, byteorder=’little’)
4096
int.from_bytes(b’\xfc\x00’, byteorder=’big’, signed=True)
-1024
int.from_bytes(b’\xfc\x00’, byteorder=’big’, signed=False)
64512
int.from_bytes([255, 0, 0], byteorder=’big’)
16711680

int.to_bytes(length, byteorder, *, signed=False)
Return an array of bytes representing an integer
返回代表对应整数的字节系列

(1024).to_bytes(2, byteorder=’big’)
b’\x04\x00’
(1024).to_bytes(5, byteorder=’big’)
b’\x00\x00\x00\x04\x00’
(1024).to_bytes(5, byteorder=’little’)
b’\x00\x04\x00\x00\x00’
(1024).to_bytes(5, byteorder=’little’,signed=True)
b’\x00\x04\x00\x00\x00’
(1024).to_bytes(5, byteorder=’little’,signed=False)
b’\x00\x04\x00\x00\x00’
(1024).to_bytes(5, byteorder=’big’,signed=False)
b’\x00\x00\x00\x04\x00’

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值