什么是“&"在python bytearray中代表

编程入门 行业动态 更新时间:2024-10-23 19:24:40
本文介绍了什么是“&"在python bytearray中代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在python bytearray末尾的&符号&是什么意思?

What does an ampersand & mean at the end of a python bytearray?

例如:

x_w = bytearray(b'\x00\x00\x04\x12\xaa\x12\x12&')

通过

int.from_bytes(x_w, 'little') Out[1]: 2743275644678045696

与没有'&'的相同字节数组给出的结果不同:

it gives a different result from the same bytearray without the '&':

x_wo = bytearray(b'\x00\x00\x04\x12\xaa\x12\x12') int.from_bytes(x_wo, 'little') Out[2]: 5087071236784128

我检查了文档,但没有找到一个答案.谢谢!

I checked the documentation but haven't found an answer to this. Thanks!

推荐答案

它只是值26(十进制38)的字节的表示形式,它是ASCII中的'&'字符.

It's simply the representation of the byte with value 26 (decimal 38), which is the '&' character in ASCII.

如果您打印所使用的字节文字的实际字节值,则可以清楚地看到这一点:

If you print the actual byte values of the bytes literal you used, you can see this clearly:

>>> print(' '.join('%02x' % b for b in b'\x00\x00\x04\x12\xaa\x12\x12&')) 00 00 04 12 aa 12 12 26

bytearray对象的repr倾向于使用ASCII字符而不是十六进制转义符来表示字节.因此,即使它们在技术上是等效的,它也会更喜欢'&'而不是'\x26'表示形式:

And the repr of the bytearray object prefers to represent bytes using ASCII characters rather than hex escapes whenever possible. So it will prefer the representation '&' rather than '\x26', even though they are technically equivalent:

>>> bytearray([0x00, 0x00, 0x04, 0x12, 0xAA, 0x12, 0x12, 0x26]) bytearray(b'\x00\x00\x04\x12\xaa\x12\x12&') >>> b'\x26' == b'&' True

更多推荐

什么是“&"在python bytearray中代表

本文发布于:2023-11-25 02:45:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代表   quot   amp   bytearray   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!