推荐学习书目
› 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 · 5242 views
    This topic created in 1757 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
        1
    livexia  
       Dec 10, 2021 via iPhone   ❤️ 1
    livexia
        2
    livexia  
       Dec 10, 2021 via iPhone
    很久前翻译的了,现在看来翻译的好像有些问题。还是推荐直接看原文吧。
    sagaxu
        3
    sagaxu  
       Dec 10, 2021 via Android
    要无缝支持无限精度,总要付出成本
    ipwx
        4
    ipwx  
       Dec 10, 2021
    可是 python 对于小整数是复用对象的嘛(对象池)

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

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