• 输出:
    python2
    print — 作为一个关键字
    python3
    print() — 作为一个函数
  • 除法:
    / 号在py2中的结果是整数,在py3中的结果是浮点数
    py2中如何实现整数除法的结果为浮点数呢?引入模块
from __future__ import division
  • 比较
    py2中,字符串可以直接和数字比较,但结果不是我们通常预想的结果(实际是ascii码逐个比较?)
    py3中,字符串不能直接与数字比较,会报错,需使用int()方法。
➜  ~ python2.7 
Python 2.7.12 (default, Sep 29 2016, 12:52:02) 
[GCC 6.2.1 20160916 (Red Hat 6.2.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '1'<2
False
>>> int('1')<2
True
>>> exit()
➜  ~ python3
Python 3.5.2 (default, Sep 14 2016, 11:28:32) 
[GCC 6.2.1 20160901 (Red Hat 6.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> '1'<3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()
>>> float('1.34')<1.5
True
posted on 2017-01-18 10:19  岚漾忆雨  阅读(39)  评论(0)    收藏  举报