在Python中,字符串是对象,因此值是对象本身的大小.所以这个大小总是比字符串大小本身大.
来自stringobject.h:
typedef struct {
PyObject_VAR_HEAD
long ob_shash;
int ob_sstate;
char ob_sval[1];
/* Invariants:
* ob_sval contains space for 'ob_size+1' elements.
* ob_sval[ob_size] == 0.
* ob_shash is the hash of the string or -1 if not computed yet.
* ob_sstate != 0 iff the string object is in stringobject.c's
* 'interned' dictionary; in this case the two references
* from 'interned' to this object are *not counted* in ob_refcnt.
*/
} PyStringObject;
从这里你可以得到一些关于如何使用这些字节的线索:
> len(str)1个字节来存储字符串本身;哈希> 8个字节;>(…)