理解 rb 模式和 read() 的问题

Problems understanding rb mode and read()

我有一个名为 'testinput.txt' 的 .txt 文件,其中包含一个由八个零组成的字符串。没有别的。

在 python 中执行以下操作会将值 48 打印到终端。有人可以解释一下发生了什么吗? (我本来希望打印 0)

f = open('testinput.txt','rb')
print(f.read(1)[0])

希望有人能帮忙澄清一下。

提前致谢。

While bytes literals and representations are based on ASCII text, bytes objects actually behave like immutable sequences of integers, with each value in the sequence restricted such that 0 <= x < 256 [..]. This is done deliberately to emphasise that while many binary formats include ASCII based elements and can be usefully manipulated with some text-oriented algorithms, this is not generally the case for arbitrary binary data (blindly applying text processing algorithms to binary data formats that are not ASCII compatible will usually lead to data corruption).

https://docs.python.org/3/library/stdtypes.html#bytes

因此,访问 bytes 中的各个偏移量会得到一个数字(数字字节值;请参阅上面强调的部分)。访问 bytes 序列 会得到一个 bytes 序列:

>>> b'0'
b'0'
>>> b'0'[0]
48
>>> b'0'[0:1]
b'0'