百万年薪python之路 -- python2和python3的区别

python学习网 2019-07-05 21:28:02

python2和python3的区别:

  • python2获取的是整数 python3获取的是浮点数
  • print函数:(Python3中print为一个函数,必须用括号括起来;Python2中print为class)

  • python2:

print 'Python', python_version()
print 'Hello, World!'
print('Hello, World!')
print "text", ; print 'print more text on the same line'

运行结果:
Python 2.7.6
Hello, World!
Hello, World!
text print more text on the same line
  • python3:
print('Python', python_version())
print('Hello, World!')
print("some text,", end="")
print(' print more text on the same line')

运行结果:
Python 3.4.1
Hello, World!
some text, print more text on the same line
  • 通过input()解析用户的输入:
    • Python3中input得到的为str;
    • Python2的input的到的为int型,Python2的raw_input得到的为str类型
  • python除法:
    • Python3中/表示真除,//表示地板除(结果取整);
    • Python2中俩整数相除/表示地板除(带上小数点/表示真除),//同样表示地板除
阅读(2672) 评论(0)