1. 程式人生 > >Python2與Python3的區別收集

Python2與Python3的區別收集

python3 列表 2.7 tel edits str more 推導 test

1、python2中,在列表推導中for關鍵字之後的賦值操作可能會影響到列表推導上下文中的同名變量:

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x=‘aaa‘
>>> test = [x for x in ‘ABC‘]
>>> x
‘C‘

python3:

>>> x=‘aaa‘
>>> test = [x for x in ‘ABC‘]
>>> x
‘aaa‘

Python2與Python3的區別收集