众所周知,Python3将所有字符串字符作为Unicode代码点.
type('\x0d')
<class 'str'>
type(b'\x0d')
<class 'bytes'>
The ascii of b'\x0d'
is 13
,stored in memory in the form of 0000 0111
,'\x0d'
is stored in the same format of 0000 0111
or not?Are they equally stored in memory?
To dig more to make me more confused:
#My python version
python3 --version
Python 3.9.2
#in python cli
len(b'\x0d')
1
import sys
print(sys.getsizeof(b'\x0d'))
34
b\x0d
不是以00000111
的形式存储在内存中吗?
print(sys.getsizeof('\x0d'))
50
使用sys.getsizeof
让我明白了:
-
string
和bytes
与不同的对象一起存储在python3中. - 当我们说
b\x0d
是以00000111
的形式存储在内存中时,它是基于某种抽象级别的,实际上b\x0d
是以34个字节存储在PC的内存中用于cython3?