[1]a=[8,13,11,6,26,19,24]1)请输出列表a中的奇数项2)请输出列表a中的奇数 解:1) a=[8,13,11,6,26,19,24] print a[::2] Result:>>>[8, 11, 26, 24] 2) a = [8,13,11,6,26,19,24] b = [] for item in a: if item%2 !=0: b.append(item) else: continue print b Result:>>>[13, 1…
Python的列表就像是一个数组: 一.创建列表 movies=["The Holy Grail","Then Life of Brian","The Meaning of Life"] 这里的movies是一个变量,而且不需要声明变量的类型. 数组是从0开始计数的.如果要访问列表里的数据,可以这样: ['The Holy Grail', 'Then Life of Brian', 'The Meaning of Life'] >>&…
数字 1,加减乘除:+,-,*,/ 2,平方:** 3,立方:**3 4,字符串转换:str(数字) 5,浮点数:带小数点 0.2 Python编程建议 import this >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is…
一.在列表中筛选数据 在列表中筛选出大于等于零的数据,一般通用的用法代码如下: data = [3, -9, 0, 1, -6, 3, -2, 8, -6] #要筛选的原始数据列表 result = [] #存放筛选结果的列表 for x in data: #依次迭代循环每个元素 if x >= 0: #判断是否符合筛选条件 result.append(x) #大于等于零就将该元素加入结果列表中 print(result) #打印输出 在python 中还有更加简洁高效的方法: 1.filter…