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

Python2与Python3的区别收集

时间:2017-10-16 01:42:13      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:str   上下文   help   red   for   影响   intel   python3   form   

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的区别收集

标签:str   上下文   help   red   for   影响   intel   python3   form   

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

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