推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
ruxuan1306
V2EX  ›  Python

Python 一个整型居然最少 24 字节

  •  
  •   ruxuan1306 · Dec 10, 2021 · 5354 views
    This topic created in 1800 days ago, the information mentioned may be changed or developed.
    print(sys.getsizeof(0))        # 24
    print(sys.getsizeof(1))        # 28 
    print(sys.getsizeof(2))        # 28
    print(sys.getsizeof(2**15))    # 28
    print(sys.getsizeof(2**30))    # 32
    print(sys.getsizeof(2**128))   # 44
    
    12 replies  •  2021-12-10 13:30:09 +08:00
    livexia
    livexia
    Dec 10, 2021 via iPhone
    2
    很久前翻译的了,现在看来翻译的好像有些问题。还是推荐直接看原文吧。
    sagaxu
    sagaxu
    Dec 10, 2021 via Android
    3
    要无缝支持无限精度,总要付出成本
    ipwx
    ipwx
    Dec 10, 2021
    4
    可是 python 对于小整数是复用对象的嘛(对象池)

    而且如果你要处理大量数字,你该上 numpy
    est
    est
    Dec 10, 2021
    5
    既然有最少了,你咋不说最多多少字节呢。。。。
    sujin190
    sujin190
    Dec 10, 2021
    6
    非静态编译型语言的都这样好的吧
    skinny
    skinny
    Dec 10, 2021
    7
    我之前就吐槽过 Python 的数据类型太占内存,超过我的预期,结果被一群杠精说我代码写得太烂(满头问号)。处理大量“常驻”内存的数据还是用 C 扩展吧。
    deplivesb
    deplivesb
    Dec 10, 2021
    8
    无限长度的代价而已
    tabris17
    tabris17
    Dec 10, 2021
    9
    想要 fixed length int 可以用这个库

    pip install fixedint
    nightwitch
    nightwitch
    Dec 10, 2021
    10
    原生的数值类型用的也不多呀。
    大量的数值计算和数据处理不都是上 numpy ,pandas 这种库么
    bumz
    bumz
    Dec 10, 2021 via iPhone
    11
    jsoniter.com 域名是不是过期了
    bumz
    bumz
    Dec 10, 2021 via iPhone
    12
    @bumz 回错贴了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2139 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 05:14 · PVG 13:14 · LAX 21:14 · JFK 00:14
    ♥ Do have faith in what you're doing.