Python字节不打印二进制 [英] Python Byte doesn't print binary

查看:117
本文介绍了Python字节不打印二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Python中打印这样的程序时:

When I print a program such as this in Python:

x = b'francis'

输出为 b'francis'。如果字节位于 0 1 中,为什么不打印出来?

The output is b'francis'. If bytes is in 0's and 1's why is it not printing it out?

推荐答案

您似乎从根本上很困惑,以一种非常普通的方式。数据本身是与表示形式不同的概念,即,当您尝试打印或以其他方式显示数据时所看到的内容。表示相同数据的方法可能有多种。这就像我写 23 (十进制)或 0x17 (十六进制)或 0o27 (八进制)或 0b10111 (二进制)或二十三(英语) ,我正在谈论相同的数字

You seem to be fundamentally confused, in a very common way. The data itself is a distinct concept from its representation, i.e. what you see when you attempt to print it out or otherwise display it. There may be multiple ways to represent the same data. This is just like how if I write 23 (in decimal) or 0x17 (hexadecimal) or 0o27 (octal) or 0b10111 (binary) or twenty-three (English), I am talking about the same number.

在Python下方的某个较低级别,一切是字节,并且每个字节由位组成;但是说字节在 0 s和 1 不是 > s-就像不正确地说数字十三是十进制数字(或十六进制,八进制或二进制数字,或英文文本字符)一样。

At some lower level below Python, everything is bytes, and each byte consists of bits; but it is not correct to say that the bytes "are in" 0s and 1s - just like how it is not correct to say that the number twenty-three "is in" decimal digits (or hexadecimal, octal or binary ones, or in English text characters).

符号 0 1 只是我们在屏幕上绘制的表示状态的图片这些位-如果我们选择分别代表它们。有时,我们选择较大的分组,然后将不同的符号分配给状态的各种组合。例如,我们可以将多个位解释为二进制形式的单个整数值。或(使用Unicode),我们可能会进一步将该数字解释为代码点(大多数是文本字符;一些是控制字符或部分文本字符)。

The symbols 0 and 1 are just pictures that we draw on a screen to represent the state of those bits - if we choose to represent them individually. Sometimes, we choose larger groupings, and assign different symbols to various combinations of states. For example, we may interpret multiple bits as a single integer value in binary; or (using Unicode) we might further interpret that number as a "code point" (most of these are text characters; some are control characters, or portions of text characters).

Python bytes 对象是原始字节序列的包装。在显示时,Python使用一种表示形式,其中每个字节(8位分组)对应一个或多个符号:(由于历史原因)其对应的整数值在32到126之间(包括32和126)的字节。用单个文本字符表示(遵循所谓的ASCII编码),而其他字符则用四个字符的转义序列表示,以 \x 开头,后跟数字的十六进制表示形式。

A Python bytes object is a wrapper for a "raw" sequence of bytes. When you display it, Python uses a representation where each byte (grouping of 8 bits) corresponds to one or more symbols: bytes whose corresponding integer value is between thirty-two and one hundred twenty-six (inclusive) are (for historical reasons) represented using individual text characters (following the so-called ASCII encoding), while others are represented with a four-character "escape sequence" beginning with \x and followed by the hexadecimal representation of the number.

这篇关于Python字节不打印二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆