Fork me on GitHub

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'

 

posted @ 2017-10-15 23:48  流氓兔Nemo  阅读(152)  评论(0编辑  收藏  举报