为什么Python中的空字符串有时占用49字节,有时占用51字节?
- 论坛
- 为什么Python中的空字符串有时占用49字节,有时占用51字节?
10 浏览
为什么Python中的空字符串有时占用49字节,有时占用51字节?
我在三个环境中测试了sys.getsize('')
和sys.getsize(' ')
,在其中两个环境中,sys.getsize('')
给出的结果是51字节(比第二个多一个字节),而不是49字节:
截图:
Win8 + Spyder + CPython 3.6:
Win8 + Spyder + IPython 3.6:
Win10 (VPN远程) + PyCharm + CPython 3.7:
第一次编辑
我在Python.exe中进行了第二次测试,而不是在Spyder和PyCharm中(这两个仍然显示为51),一切似乎都很正常。显然我没有解决这个问题的专业知识,所以我把它留给你们解决吧 🙂
Win10 + Python 3.7控制台与使用相同解释器的PyCharm进行对比:
Win8 + IPython 3.6 + 使用相同解释器的Spyder: