# #-*- coding: utf-8 -*-'''@author: soyo'''import numpyimport pandas import math as mfrom _ctypes import Arrayfrom _collections import dequea="soyo"b=200s=0c=b%6d=m.sqrt(25)while b: s+=b b-=1print sprint dfor a in ['e','f','g']: print afor a in "soyo": print afor a in [1,2,"soyo",8,9]: print a if a=="soyo": for b in a: print b f=range(20)for a in f: print a if a==10: print "soyo88"w=range(3,8)for a in w: print a r=range(2,15,3)for a in r: print aprint "*************" l=[1,2,3]for a in l: a+=1; print a print lprint "******************"for i in range(len(l)): l[i]+=1 print l[i] else: print "soyosoyo"print lprint len(l) print "************列表操作***********" print "列表切片操作:"p=[1,2,4,5,22,66,78,89,"soyo",56,22,88,22]p3=["soyo2",778,999]print p[0]print p[1]print p[-1]print p[-2]p2=p[1:5]print p2print "列表添加操作"p.append(100)print pprint "/*/*/*/*/*"p.append(p2) #想要去掉新列表中的[]改用p.extend(p2)print p print "/*/*/*/*/*"print p[-1]for a in p[-1]: print ap.insert(2, "soyo5")print pp.remove(4)print pp.pop(2)print pprint p.index("soyo")print "//"print pprint p.count(2)p.sort()print pp.reverse()print pprint "列表 用作栈"p4=[1,2,5]p4.append(20)p4.append(98)print p4p4.pop()print p4.pop() #出栈的元素print p4print "列表 用作队列" #可以实现但是效率不高print "deque 用作队列" #队列实现改用dequep6=deque([8,9,10])p6.append(11)p6.append(12)print p6p6.popleft()print p6.popleft()print p6
结果:20100
5.0efgsoyo12soyosoyo89012345678910soyo88111213141516171819345672581114*************234[1, 2, 3]******************234soyosoyo[2, 3, 4]3************列表操作***********列表切片操作:122288[2, 4, 5, 22]列表添加操作[1, 2, 4, 5, 22, 66, 78, 89, 'soyo', 56, 22, 88, 22, 100]/*/*/*/*/*[1, 2, 4, 5, 22, 66, 78, 89, 'soyo', 56, 22, 88, 22, 100, [2, 4, 5, 22]]/*/*/*/*/*[2, 4, 5, 22]24522[1, 2, 'soyo5', 4, 5, 22, 66, 78, 89, 'soyo', 56, 22, 88, 22, 100, [2, 4, 5, 22]][1, 2, 'soyo5', 5, 22, 66, 78, 89, 'soyo', 56, 22, 88, 22, 100, [2, 4, 5, 22]][1, 2, 5, 22, 66, 78, 89, 'soyo', 56, 22, 88, 22, 100, [2, 4, 5, 22]]7//[1, 2, 5, 22, 66, 78, 89, 'soyo', 56, 22, 88, 22, 100, [2, 4, 5, 22]]1[1, 2, 5, 22, 22, 22, 56, 66, 78, 88, 89, 100, [2, 4, 5, 22], 'soyo']['soyo', [2, 4, 5, 22], 100, 89, 88, 78, 66, 56, 22, 22, 22, 5, 2, 1]列表 用作栈[1, 2, 5, 20, 98]20[1, 2, 5]列表 用作队列deque 用作队列deque([8, 9, 10, 11, 12])9deque([10, 11, 12])