Python3.x和python2.x 3.x的区别

Python2.x与Python3.x的区别
Python的3​​.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下相容。许多针对早期Python版本设计的程式都无法在Python 3.0上正常执行。为了照顾现有程式,Python 2.6作为一个过渡版本,基本使用了Python 2.x的语法和库,同时考虑了向Python 3.0的迁移,允许使用部分Python 3.0的语法与函数。新的Python程式建议使用Python 3.0版本的语法。除非执行环境无法安装Python 3.0或者程式本身使用了不支援Python 3.0的第三方库。目前不支援Python 3.0的第三方库有Twisted, py2exe, PIL等。大多数第三方库都正在努力地相容Python 3.0版本。即使无法立即使用Python 3.0,也建议编写相容Python 3.0版本的程式,然后使用Python 2.6, Python 2.7来执行。1.性能 Py3.0运行 pystone benchmark的速度比Py2.5慢30%。Guido认为Py3.0有极大的优化空间,在字符串和整形操作上可 以取得很好的优化结果。 Py3.1性能比Py2.5慢15%,还有很大的提升空间。2.编码Py3.X源码文件默认使用utf-8编码,这就使得以下代码是合法的: &&& 中国 = 'china' &&&print(中国) china3. 语法 1)去除了&&,全部改用!= 2)去除``,全部改用repr() 3)关键词加入as 和with,还有True,False,None 4)整型除法返回浮点数,要得到整型结果,请使用// 5)加入nonlocal语句。使用noclocal x可以直接指派外围(非全局)变量 6)去除print语句,加入print()函数实现相同的功能。同样的还有 exec语句,已经改为exec()函数例如: 2.X: print "The answer is", 2*2 3.X: print("The answer is", 2*2) 2.X: print x, # 使用逗号结尾禁止换行 3.X: print(x, end=" ") # 使用空格代替换行 2.X: print # 输出新行 3.X: print() # 输出新行 2.X: print &&sys.stderr, "fatal error" 3.X: print("fatal error", file=sys.stderr) 2.X: print (x, y) # 输出repr((x, y)) 3.X: print((x, y)) # 不同于print(x, y)! 7)改变了顺序操作符的行为,例如x&y,当x和y类型不匹配时抛出TypeError而不是返回随即的 bool值 8)输入函数改变了,删除了raw_input,用input代替: 2.X:guess = int(raw_input('Enter an integer : ')) # 读取键盘输入的方法 3.X:guess = int(input('Enter an integer : ')) 9)去除元组参数解包。不能def(a, (b, c)):pass这样定义函数了 10)新式的8进制字变量,相应地修改了oct()函数。2.X的方式如下: &&& 0666 438 &&& oct(438) '0666' 3.X这样:&&& 0666 SyntaxError: invalid token (&pyshell#63&, line 1) &&& 0o666 438 &&& oct(438) '0o666'11)增加了 2进制字面量和bin()函数 &&& bin(438) '0b' &&& _438 = '0b' &&& _438 '0b' 12)扩展的可迭代解包。在Py3.X 里,a, b, *rest = seq和 *rest, a = seq都是合法的,只要求两点:rest是list 对象和seq是可迭代的。 13)新的super(),可以不再给super()传参数, &&& class C(object): def __init__(self, a): print('C', a) &&& class D(C): def __init(self, a): super().__init__(a) # 无参数调用super() &&& D(8) C 8 &__main__.D object at 0x00D7ED90&14)新的metaclass语法: class Foo(*bases, **kwds): pass 15)支持class decorator。用法与函数decorator一样: &&& def foo(cls_a): def print_func(self): print('Hello, world!') cls_a.print = print_func return cls_a &&& @foo class C(object): pass &&& C().print() Hello, world! class decorator可以用来玩玩狸猫换太子的大把戏。更多请参阅PEP 31294. 字符串和字节串 1)现在字符串只有str一种类型,但它跟2.x版本的unicode几乎一样。 2)关于字节串,请参阅“数据类型”的第2条目5.数据类型1)Py3.X去除了long类型,现在只有一种整型――int,但它的行为就像2.X版本的long 2)新增了bytes类型,对应于2.X版本的八位串,定义一个bytes字面量的方法如下: &&& b = b'china' &&& type(b) &type 'bytes'& str对象和bytes对象可以使用.encode() (str -& bytes) or .decode() (bytes -& str)方法相互转化。 &&& s = b.decode() &&& s 'china' &&& b1 = s.encode() &&& b1 b'china' 3)dict的.keys()、.items 和.values()方法返回迭代器,而之前的iterkeys()等函数都被废弃。同时去掉的还有 dict.has_key(),用 in替代它吧6.面向对象 1)引入抽象基类(Abstraact Base Classes,ABCs)。 2)容器类和迭代器类被ABCs化,所以cellections模块里的类型比Py2.5多了很多。 &&& import collections &&& print('/n'.join(dir(collections))) Callable Container Hashable ItemsView Iterable Iterator KeysView Mapping MappingView MutableMapping MutableSequence MutableSet NamedTuple Sequence Set SizedValuesView __all__ __builtins__ __doc__ __file__ __name__ _abcoll _itemgetter _sys defaultdict deque另外,数值类型也被ABCs化。关于这两点,请参阅 PEP 3119和PEP 3141。3)迭代器的next()方法改名为__next__(),并增加内置函数next(),用以调用迭代器的__next__()方法 4)增加了@abstractmethod和 @abstractproperty两个 decorator,编写抽象方法(属性)更加方便。7.异常1)所以异常都从 BaseException继承,并删除了StardardError 2)去除了异常类的序列行为和.message属性 3)用 raise Exception(args)代替 raise Exception, args语法 4)捕获异常的语法改变,引入了as关键字来标识异常实例,在Py2.5中: &&& try: ... raise NotImplementedError('Error') ... except NotImplementedError, error: ... print error.message ... Error 在Py3.0中: &&& try: raise NotImplementedError('Error') except NotImplementedError as error: #注意这个 as print(str(error)) Error 5)异常链,因为__context__在3.0a1版本中没有实现8.模块变动 1)移除了cPickle模块,可以使用pickle模块代替。最终我们将会有一个透明高效的模块。 2)移除了imageop模块 3)移除了 audiodev, Bastion, bsddb185, exceptions, linuxaudiodev, md5, MimeWriter, mimify, popen2, rexec, sets, sha, stringold, strop, sunaudiodev, timing和xmllib模块 4)移除了bsddb模块(单独发布,可以从http://www.jcea.es/programacion/pybsddb.htm获取) 5)移除了new模块 6)os.tmpnam()和os.tmpfile()函数被移动到tmpfile模块下 7)tokenize模块现在使用bytes工作。主要的入口点不再是generate_tokens,而是 tokenize.tokenize()9.其它 1)xrange() 改名为range(),要想使用range()获得一个list,必须显式调用: &&& list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 2)bytes对象不能hash,也不支持 b.lower()、b.strip()和b.split()方法,但对于后两者可以使用 b.strip(b' /n/t/r /f')和b.split(b' ‘)来达到相同目的 3)zip()、map()和filter()都返回迭代器。而apply()、 callable()、coerce()、 execfile()、reduce()和reload ()函数都被去除了现在可以使用hasattr()来替换 callable(). hasattr()的语法如:hasattr(string, '__name__')4)string.letters和相关的.lowercase和.uppercase被去除,请改用string.ascii_letters 等 5)如果x & y的不能比较,抛出TypeError异常。2.x版本是返回伪随机布尔值的 6)__getslice__系列成员被废弃。a[i:j]根据上下文转换为a.__getitem__(slice(I, j))或 __setitem__和 __delitem__调用 7)file类被废弃,在Py2.5中: &&& file &type 'file'& 在Py3.X中: &&& file Traceback (most recent call last): File "&pyshell#120&", line 1, in &module& file NameError: name 'file' is not defined python2.x与python3.x在除法运算上的区别Python中的除法较其它语言显得非常高端,有套很复杂的规则。Python中的除法有两个运算符,/和//首先来说/除法:在python 2.x中/除法就跟我们熟悉的大多数语言,比如Java啊C啊差不多,整数相除的结果是一个整数,把小数部分完全忽略掉,浮点数除法会保留小数点的部分得到一个浮点数的结果。在python 3.x中/除法不再这么做了,对于整数之间的相除,结果也会是浮点数。Python 2.x:&&& 1 / 20&&& 1.0 / 2.00.5Python 3.x:&&& 1/20.5而对于//除法,这种除法叫做floor除法,会对除法的结果自动进行一个floor操作,在python 2.x和python 3.x中是一致的。python 2.x:&&& -1 // 2-1python 3.x:&&& -1 // 2-1注意的是并不是舍弃小数部分,而是执行floor操作,如果要截取小数部分,那么需要使用math模块的trunc函数python 3.x:&&& import math&&& math.trunc(1 / 2)0&&& math.trunc(-1 / 2)0以上内容给大家介绍了Python2.x与Python3.x的区别,希望对大家有所帮助。您可能感兴趣的文章:Python3.x和Python2.x的区别介绍编写同时兼容Python2.x与Python3.x版本的代码的几个示例Python2.x和3.x下maketrans与translate函数使用上的不同把项目从Python2.x移植到Python3.x的经验总结Windows下使Python2.x版本的解释器与3.x共存的方法
无相关信息
最新教程周点击榜
微信扫一扫Python 2.7.x 和 3.x 版本的重要区别小结
投稿:mdxy-dxy
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了Python 2.7.x 和 3.x 版本的重要区别小结,需要的朋友可以参考下
许多Python初学者都会问:我应该学习哪个版本的Python。对于这个问题,我的回答通常是“先选择一个最适合你的Python教程,教程中使用哪个版本的Python,你就用那个版本。等学得差不多了,再来研究不同版本之间的差别”。
但如果想要用Python开发一个新项目,那么该如何选择Python版本呢?我可以负责任的说,大部分Python库都同时支持Python 2.7.x和3.x版本的,所以不论选择哪个版本都是可以的。但为了在使用Python时避开某些版本中一些常见的陷阱,或需要移植某个Python项目时,依然有必要了解一下Python两个常见版本之间的主要区别。
__future__模块
Python 3.x引入了一些与Python 2不兼容的关键字和特性,在Python 2中,可以通过内置的__future__模块导入这些新内容。如果你希望在Python 2环境下写的代码也可以在Python 3.x中运行,那么建议使用__future__模块。例如,如果希望在Python 2中拥有Python 3.x的整数除法行为,可以通过下面的语句导入相应的模块。
from __future__ import division
下表列出了__future__中其他可导入的特性:
nested_scopes
Statically Nested Scopes
generators
Simple Generators
Changing the Division Operator
absolute_import
Imports: Multi-Line and Absolute/Relative
with_statement
The “with” Statement
print_function
Make print a function
unicode_literals
Bytes literals in Python 3000
(来源: )
from platform import python_version
虽然print语法是Python 3中一个很小的改动,且应该已经广为人知,但依然值得提一下:Python 2中的print语句被Python 3中的print()函数取代,这意味着在Python 3中必须用括号将需要输出的对象括起来。
在Python 2中使用额外的括号也是可以的。但反过来在Python 3中想以Python2的形式不带括号调用print函数时,会触发SyntaxError。
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
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
print 'Hello, World!'
File "&ipython-input-3-139a7c5835bd&", line 1
print 'Hello, World!'
SyntaxError: invalid syntax
在Python中,带不带括号输出”Hello World”都很正常。但如果在圆括号中同时输出多个对象时,就会创建一个元组,这是因为在Python 2中,print是一个语句,而不是函数调用。
print 'Python', python_version()
print('a', 'b')
print 'a', 'b'
Python 2.7.7
('a', 'b')
由于人们常常会忽视Python 3在整数除法上的改动(写错了也不会触发Syntax Error),所以在移植代码或在Python 2中执行Python 3的代码时,需要特别注意这个改动。
所以,我还是会在Python 3的脚本中尝试用float(3)/2或 3/2.0代替3/2,以此来避免代码在Python 2环境下可能导致的错误(或与之相反,在Python 2脚本中用from __future__ import division来使用Python 3的除法)。
print 'Python', python_version()
print '3 / 2 =', 3 / 2
print '3 // 2 =', 3 // 2
print '3 / 2.0 =', 3 / 2.0
print '3 // 2.0 =', 3 // 2.0
Python 2.7.6
3 // 2 = 1
3 / 2.0 = 1.5
3 // 2.0 = 1.0
print('Python', python_version())
print('3 / 2 =', 3 / 2)
print('3 // 2 =', 3 // 2)
print('3 / 2.0 =', 3 / 2.0)
print('3 // 2.0 =', 3 // 2.0)
Python 3.4.1
3 / 2 = 1.5
3 // 2 = 1
3 / 2.0 = 1.5
3 // 2.0 = 1.0
Python 2有基于ASCII的str()类型,其可通过单独的unicode()函数转成unicode类型,但没有byte类型。
而在Python 3中,终于有了Unicode(utf-8)字符串,以及两个字节类:bytes和bytearrays。
print 'Python', python_version()
Python 2.7.6
print type(unicode('this is like a python3 str type'))
&type 'unicode'&
print type(b'byte type does not exist')
&type 'str'&
print 'they are really' + b' the same'
they are really the same
print type(bytearray(b'bytearray oddly does exist though'))
&type 'bytearray'&
print('Python', python_version())
print('strings are now utf-8 u03BCnicou0394é!')
Python 3.4.1
strings are now utf-8 μnicoΔé!
print('Python', python_version(), end="")
print(' has', type(b' bytes for storing data'))
Python 3.4.1 has &class 'bytes'&
print('and Python', python_version(), end="")
print(' also has', type(bytearray(b'bytearrays')))
and Python 3.4.1 also has &class 'bytearray'&
'note that we cannot add a string' + b'bytes for data'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
&ipython-input-13-d3e8942ccf81& in &module&()
----& 1 'note that we cannot add a string' + b'bytes for data'
TypeError: Can't convert 'bytes' object to str implicitly
在Python 2.x中,经常会用xrange()创建一个可迭代对象,通常出现在“for循环”或“列表/集合/字典推导式”中。
这种行为与生成器非常相似(如”惰性求值“),但这里的xrange-iterable无尽的,意味着可能在这个xrange上无限迭代。
由于xrange的“惰性求知“特性,如果只需迭代一次(如for循环中),range()通常比xrange()快一些。不过不建议在多次迭代中使用range(),因为range()每次都会在内存中重新生成一个列表。
在Python 3中,range()的实现方式与xrange()函数相同,所以就不存在专用的xrange()(在Python 3中使用xrange()会触发NameError)。
import timeit
def test_range(n):
return for i in range(n):
def test_xrange(n):
for i in xrange(n):
print 'Python', python_version()
print 'ntiming range()'
%timeit test_range(n)
print 'nntiming xrange()'
%timeit test_xrange(n)
Python 2.7.6
timing range()
1000 loops, best of 3: 433 &s per loop
timing xrange()
1000 loops, best of 3: 350 &s per loop
print('Python', python_version())
print('ntiming range()')
%timeit test_range(n)
Python 3.4.1
timing range()
1000 loops, best of 3: 520 &s per loop
print(xrange(10))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
----& 1 print(xrange(10))
NameError: name 'xrange' is not defined
Python 3中的range对象中的__contains__方法
另一个值得一提的是,在Python 3.x中,range有了一个新的__contains__方法。__contains__方法可以有效的加快Python 3.x中整数和布尔型的“查找”速度。
def val_in_range(x, val):
return val in range(x)
def val_in_xrange(x, val):
return val in xrange(x)
print('Python', python_version())
assert(val_in_range(x, x/2) == True)
assert(val_in_range(x, x//2) == True)
%timeit val_in_range(x, x/2)
%timeit val_in_range(x, x//2)
Python 3.4.1
1 loops, best of 3: 742 ms per loop
1000000 loops, best of 3: 1.19 &s per loop
根据上面的timeit的结果,查找整数比查找浮点数要快大约6万倍。但由于Python 2.x中的range或xrange没有__contains__方法,所以在Python 2中的整数和浮点数的查找速度差别不大。
print 'Python', python_version()
assert(val_in_xrange(x, x/2.0) == True)
assert(val_in_xrange(x, x/2) == True)
assert(val_in_range(x, x/2) == True)
assert(val_in_range(x, x//2) == True)
%timeit val_in_xrange(x, x/2.0)
%timeit val_in_xrange(x, x/2)
%timeit val_in_range(x, x/2.0)
%timeit val_in_range(x, x/2)
Python 2.7.7
1 loops, best of 3: 285 ms per loop
1 loops, best of 3: 179 ms per loop
1 loops, best of 3: 658 ms per loop
1 loops, best of 3: 556 ms per loop
下面的代码证明了Python 2.x中没有__contain__方法:
print('Python', python_version())
range.__contains__
Python 3.4.1
&slot wrapper '__contains__' of 'range' objects
print('Python', python_version())
range.__contains__
Python 2.7.7
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
&ipython-input-7-dafb& in &module&()
1 print 'Python', python_version()
----& 2 range.__contains__
AttributeError: 'builtin_function_or_method' object has no attribute '__contains__'
print('Python', python_version())
xrange.__contains__
Python 2.7.7
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
1 print 'Python', python_version()
----& 2 xrange.__contains__
AttributeError: type object 'xrange' has no attribute '__contains__'
关于Python 2中xrange()与Python 3中range()之间的速度差异的一点说明:
有读者指出了Python 3中的range()和Python 2中xrange()执行速度有差异。由于这两者的实现方式相同,因此理论上执行速度应该也是相同的。这里的速度差别仅仅是因为Python 3的总体速度就比Python 2慢。
def test_while():
while i & 20000:
print('Python', python_version())
%timeit test_while()
Python 3.4.1
%timeit test_while()
100 loops, best of 3: 2.68 ms per loop
print 'Python', python_version()
%timeit test_while()
Python 2.7.6
1000 loops, best of 3: 1.72 ms per loop
Python 2支持新旧两种异常触发语法,而Python 3只接受带括号的的语法(不然会触发SyntaxError):
print 'Python', python_version()
Python 2.7.6
raise IOError, "file error"
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
&ipython-input-8-25f049caebb0& in &module&()
----& 1 raise IOError, "file error"
IOError: file error
raise IOError("file error")
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
&ipython-input-9-6f1c43f525b2& in &module&()
----& 1 raise IOError("file error")
IOError: file error
print('Python', python_version())
Python 3.4.1
raise IOError, "file error"
File "&ipython-input-10-25f049caebb0&", line 1
raise IOError, "file error"
SyntaxError: invalid syntax
The proper way to raise an exception in Python 3:
print('Python', python_version())
raise IOError("file error")
Python 3.4.1
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
&ipython-input-11-cda& in &module&()
1 print('Python', python_version())
----& 2 raise IOError("file error")
OSError: file error
Python 3中的异常处理也发生了一点变化。在Python 3中必须使用“as”关键字。
print 'Python', python_version()
let_us_cause_a_NameError
except NameError, err:
print err, '--& our error message'
Python 2.7.6
name 'let_us_cause_a_NameError' is not defined --& our error message
print('Python', python_version())
let_us_cause_a_NameError
except NameError as err:
print(err, '--& our error message')
Python 3.4.1
name 'let_us_cause_a_NameError' is not defined --& our error message
next()函数和.next()方法
由于会经常用到next()(.next())函数(方法),所以还要提到另一个语法改动(实现方面也做了改动):在Python 2.7.5中,函数形式和方法形式都可以使用,而在Python 3中,只能使用next()函数(试图调用.next()方法会触发AttributeError)。
print 'Python', python_version()
my_generator = (letter for letter in 'abcdefg')
next(my_generator)
my_generator.next()
Python 2.7.6
print('Python', python_version())
my_generator = (letter for letter in 'abcdefg')
next(my_generator)
Python 3.4.1
my_generator.next()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
&ipython-input-14-125f388bb61b& in &module&()
----& 1 my_generator.next()
AttributeError: 'generator' object has no attribute 'next'
For循环变量与全局命名空间泄漏
好消息是:在Python 3.x中,for循环中的变量不再会泄漏到全局命名空间中了!
这是Python 3.x中做的一个改动,在“What's New In Python 3.0”中有如下描述:
“列表推导不再支持[... for var in item1, item2, ...]这样的语法,使用[... for var in (item1, item2, ...)]代替。还要注意列表推导有不同的语义:现在列表推导更接近list()构造器中的生成器表达式这样的语法糖,特别要注意的是,循环控制变量不会再泄漏到循环周围的空间中了。”
print 'Python', python_version()
print 'before: i =', i
print 'comprehension: ', [i for i in range(5)]
print 'after: i =', i
Python 2.7.6
before: i = 1
comprehension: [0, 1, 2, 3, 4]
after: i = 4
print('Python', python_version())
print('before: i =', i)
print('comprehension:', [i for i in range(5)])
print('after: i =', i)
Python 3.4.1
before: i = 1
comprehension: [0, 1, 2, 3, 4]
after: i = 1
比较无序类型
Python 3中另一个优秀的改动是,如果我们试图比较无序类型,会触发一个TypeError。
print 'Python', python_version()
print "[1, 2] & 'foo' = ", [1, 2] & 'foo'
print "(1, 2) & 'foo' = ", (1, 2) & 'foo'
print "[1, 2] & (1, 2) = ", [1, 2] & (1, 2)
Python 2.7.6
[1, 2] & 'foo' = False
(1, 2) & 'foo' = True
[1, 2] & (1, 2) = False
print('Python', python_version())
print("[1, 2] & 'foo' = ", [1, 2] & 'foo')
print("(1, 2) & 'foo' = ", (1, 2) & 'foo')
print("[1, 2] & (1, 2) = ", [1, 2] & (1, 2))
Python 3.4.1
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
&ipython-input-16-aa0& in &module&()
1 print('Python', python_version())
----& 2 print("[1, 2] & 'foo' = ", [1, 2] & 'foo')
3 print("(1, 2) & 'foo' = ", (1, 2) & 'foo')
4 print("[1, 2] & (1, 2) = ", [1, 2] & (1, 2))
TypeError: unorderable types: list() & str()
通过input()解析用户的输入
幸运的是,Python 3改进了input()函数,这样该函数就会总是将用户的输入存储为str对象。在Python 2中,为了避免读取非字符串类型会发生的一些危险行为,不得不使用raw_input()代替input()。
Python 2.7.6
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&&& my_input = input('enter a number: ')
enter a number: 123
&&& type(my_input)
&type 'int'&
&&& my_input = raw_input('enter a number: ')
enter a number: 123
&&& type(my_input)
&type 'str'&
Python 3.4.1
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&&& my_input = input('enter a number: ')
enter a number: 123
&&& type(my_input)
&class 'str'&
返回可迭代对象,而不是列表
在xrange一节中可以看到,某些函数和方法在Python中返回的是可迭代对象,而不像在Python 2中返回列表。
由于通常对这些对象只遍历一次,所以这种方式会节省很多内存。然而,如果通过生成器来多次迭代这些对象,效率就不高了。
此时我们的确需要列表对象,可以通过list()函数简单的将可迭代对象转成列表。
print 'Python', python_version()
print range(3)
print type(range(3))
Python 2.7.6
&type 'list'&
print('Python', python_version())
print(range(3))
print(type(range(3)))
print(list(range(3)))
Python 3.4.1
range(0, 3)
&class 'range'&
下面列出了Python 3中其他不再返回列表的常用函数和方法:
字典的.key()方法
字典的.value()方法
字典的.item()方法
更多关于Python 2和Python 3的文章
下面列出了其他一些可以进一步了解Python 2和Python 3的优秀文章,
//迁移到 Python 3
// 对Python 3的褒与贬
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 python2.x 3.x 的文章

 

随机推荐