Python2与Python3的区别收集

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'

原文地址:https://www.cnblogs.com/nemolmt/p/7675125.html