【发布时间】:2020-09-21 11:53:25
【问题描述】:
以下代码返回 35 作为答案:
print(sys.getsizeof((1024).to_bytes(2, byteorder='big')))
不应该 int.to_bytes() 返回 1024 的字节表示,它是 2 个字节长,因为文档提到:
The integer is represented using length bytes. An OverflowError is raised if the integer is not representable with the given number of bytes.
我理解错了什么?
【问题讨论】:
标签: python-3.x byte sizeof