• Python 2 与 python 3的区别


    1. python3已经将print置为内置函数,因此输出用print()
    2. round()四舍五入函数:
    helloworld@LG-virtual-machine:~/code$ python3.5
    Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> round(0.5)
    0
    
    • python3.5的doc中,文档变成了"values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice." 如果距离两边一样远,会保留到偶数的一边。比如round(0.5)和round(-0.5)都会保留到0,而round(1.5)会保留到2。
    helloworld@LG-virtual-machine:~/code$ python
    Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> round(0.5)
    1.0
    
    • 在python2.7的doc中,round()的最后写着,"Values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done away from 0." 保留值将保留到离上一位更近的一端,如果距离两端一样远,则保留到离0远的一边
  • 相关阅读:
    JSP/Servlet开发——第二章 JSP数据交互(二)
    JSP/Servlet开发——第一章 动态网页基础
    Java OOP——第三章 多态
    Java OOP——第二章 继承
    Java OOP——第一章 对象和封装
    Java OOP——第四章 异常
    Linux 系统启动过程
    动画链接
    js判断浏览器类型
    localStorage封装
  • 原文地址:https://www.cnblogs.com/qiulinzhang/p/9513627.html
Copyright © 2020-2023  润新知