码迷,mamicode.com
首页 > 编程语言 > 详细

【320】Python 2.x 与 3.x 的区别

时间:2018-06-21 11:32:36      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:NPU   代码   inter   proc   href   .net   bsp   targe   python3   

通过代码移植的报错进行梳理!

 

1. print 函数的区别

  Python 2.x 中可以加空格或者括号,但是 Python 3.x 只能是括号的

# Python 2.x
>>> print "processing..."
processing...
>>> print("processing...")
processing...

# Python 3.x
>>> print("processing...")
processing...

 

2. raw_input 与 input 函数

  Python 2.x 中 raw_input 与 Python 3.x 中 input 函数类似,而 Python 2.x 中的 input 函数接收数字或者带引号字符串

# Python 2.x
>>> a = raw_input("Value: ")
Value: Alex
>>> a
‘Alex‘
>>> b = input("Value: ")
Value: "Alex"
>>> b
‘Alex‘

# Python 3.x
>>> a = input("Value: ")
Value: Alex
>>> a
‘Alex‘

参考:python2.x和python3.x中raw_input( )和input( )区别

 

3. Tkinter 模块

  Python 2.x 为 Tkinter,但是 Python 3.x 为 tkinter(小写)

# Python 2.x
>>> import Tkinter

# Python 3.x
>>> import tkinter

参考:Python GUI编程(Tkinter)

 

4. 除法运算符

  Python 2.x 中 /、// 均为整除,但是 Python 3.x 中 / 表示除以,// 表示整除

# Python 2.x
>>> 77/60
1
>>> 77//60
1

# Python 3.x
>>> 77/60
1.2833333333333334
>>> int(77/60)
1
>>> 77//60
1

 

【320】Python 2.x 与 3.x 的区别

标签:NPU   代码   inter   proc   href   .net   bsp   targe   python3   

原文地址:https://www.cnblogs.com/alex-bn-lee/p/9206979.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!