V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
ericbize
V2EX  ›  Python

请教各位大神一个问题

  •  
  •   ericbize · 2017-07-08 02:04:32 +08:00 · 1737 次点击
    这是一个创建于 2446 天前的主题,其中的信息可能已经有所发展或是发生改变。
    for i in range(024,027):
    print i


    为什么输出的是
    20
    21
    22

    而不是
    24
    25
    26

    前面不加 0 却不会报错,怎么破???
    4 条回复    2017-07-12 06:20:04 +08:00
    siguretto
        1
    siguretto  
       2017-07-08 02:06:13 +08:00 via iPhone   ❤️ 3
    8 进制
    lzhr
        2
    lzhr  
       2017-07-08 02:34:37 +08:00
    daya0576
        3
    daya0576  
       2017-07-12 01:30:18 +08:00   ❤️ 1
    学会 google 呀,骚年
    https://stackoverflow.com/questions/11620151/what-do-numbers-starting-with-0-mean-in-python

    These are numbers represented in base 8 (octal numbers). For example,

    011 is equal to 1*(8**1) + 1*(8**0) = 9,
    0100 is equal to 1*(8**2) + 0*(8**1) + 0*(8**0) = 64,
    027 is equal to 2*(8**1) + 7*(8**0) = 16 + 7 = 23.
    ericbize
        4
    ericbize  
    OP
       2017-07-12 06:20:04 +08:00 via Android
    @daya0576 明白了,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5849 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:31 · PVG 11:31 · LAX 20:31 · JFK 23:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.