gpt4 book ai didi

python - 为什么 Python 数组模块以不同方式处理字符串和列表?

转载 作者:太空宇宙 更新时间:2023-11-04 11:04:18 26 4
gpt4 key购买 nike

我无法理解以下语句的结果:

>>> from array import array
>>> array('L',[0xff,0xff,0xff,0xff])
array('L', [255L, 255L, 255L, 255L])


>>> from array import array
>>> array('L','\xff\xff\xff\xff')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: string length not a multiple of item size

最佳答案

您正在 64 位 Python 版本上运行它,array 将类型代码 'L' 视为 64 位无符号整数。

>>> array('L','\xff\xff\xff\xff\xff\xff\xff\xff')
array('L', [18446744073709551615L])

文档不是很清楚。它只是说 'L' 至少有四个字节。

关于python - 为什么 Python 数组模块以不同方式处理字符串和列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2752913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com