标签:
现在我看不出来我的问题在哪里!
原题是要返回传入list or tuple的奇数位的元素,但是我用下面的方式会报错,在append那里目前,当下闭门造车,实在没有看到问题在哪里
tup = [11,12,13,14,15,16,17,18,19] lis = [] for i in range(0,len(tup),2): print tup[i] lis1 = lis.append(tup[i]) print lis1
执行结果:
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ======================= RESTART: C:/Python27/error.py ======================= 11 13 15 17 19 None >>>
没有试过Python3
但是在Linux下面直接运行也是一样的错误;
但是感觉逻辑没有问题,或者说至少暂时我没有看到问题
tup = [11,12,13,14,15,16,17,18,19] lis = [] for i in range(0,len(tup),2): a = tup[i] print lis print type(a) print a lis1 = lis.append(a) print lis1 print lis
酱紫后lis 是我想要的,但是为啥lis1却是None呢?
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ======================= RESTART: C:/Python27/error.py ======================= [] <type ‘int‘> 11 None [11] [11] <type ‘int‘> 13 None [11, 13] [11, 13] <type ‘int‘> 15 None [11, 13, 15] [11, 13, 15] <type ‘int‘> 17 None [11, 13, 15, 17] [11, 13, 15, 17] <type ‘int‘> 19 None [11, 13, 15, 17, 19] >>>
标签:
原文地址:http://www.cnblogs.com/winditsway/p/5579060.html