V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
chenstack
V2EX  ›  Python

python3 中 -123 // 10 = ?

  •  
  •   chenstack · Mar 28, 2020 · 3718 views
    This topic created in 2221 days ago, the information mentioned may be changed or developed.
    平时很少用到,一直记成整除,刷 leetcode 才重新记得 //运算符是向下取整,-123 // 10 结果是-13 。
    python 里面要像 C++那样整除是不是只能 int(-123 / 10)?但经过了浮点数转换总觉得效率不够高,有没有更好的方法?
    4 replies    2020-03-29 21:45:16 +08:00
    metamask
        1
    metamask  
       Mar 28, 2020
    math.ceil(-123/10)
    123444a
        2
    123444a  
       Mar 28, 2020 via Android
    像 0 取整,向负无穷取整
    aloxaf
        3
    aloxaf  
       Mar 28, 2020
    -(123 // 10) (
    asche910
        4
    asche910  
       Mar 29, 2020
    明确正数的话直接 // ,负数取整我看别人基本上都是 float 转换 int 。不过都用 python 了,感觉更注重的是简洁方便吧,速度还是算了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5086 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 05:39 · PVG 13:39 · LAX 22:39 · JFK 01:39
    ♥ Do have faith in what you're doing.