python3 里面的一些特性
2017-07-15 14:49
393 查看
#写 一些 python特性 mylist =[1,2,3,45,6,7,8] other =[mylist[0],mylist[1]] #取前面俩位 for i in range(3): other.append(mylist[i]) other =mylist[0:2]#取前俩位的范围 other = mylist[2:4]#去下标2到4的俩位 mylist=list(range(100))#做了一个从一到100的数 other =mylist[::2]#从开始到结束 俩个已取 other =mylist[::-2]#倒序 #循环 for a in mylist: print (a) listlen =len(mylist) for a in range(listlen): print (a) #字典的特性 mydict ={1:'a',2:'b',3:'c'} for a in mydict:#打印key print (a) for a in mydict.keys():#打印key print (a) for a in mydict:#打印value print (mydict[a]) for a in mydict.values():#打印value print (a) for a in mydict.items(): print (a) #生成器 mylist=[] for i in renge(1,11): mylist.append(i*i) #列表生成器 可以玩的很复杂 他是玩具 mylist =[x*x for x in range(1,11)] #生成器 用一次就可以扔了 gen=(x*x for x in range(1,11)) next(gen)#读一个 每一个只能读一次 #遍历生成器 不能会头 去没了 for x in gen: print (x)
相关文章推荐
- Python安装nltk以及里面一些包的使用
- python的一些特性
- python 的一些特性
- 深入Python函数编程的一些特性
- python里面的高级特性
- 本篇文档涵盖了Python.Requests 的一些高级特性
- python-网络爬虫初学二:headers的设置和一些高级特性
- 关于Python里面协程的一些理解
- Python的一些高级特性以及反序列化漏洞
- Python的函数的一些高阶特性
- 列举Python中吸引人的一些特性
- Python的类、基类、多态、取消基类的一些特性
- Python的一些特性(随笔)
- python的一些高级特性
- python的一些函数特性
- python-网络爬虫初学二:headers的设置和一些高级特性
- python--一些特性
- Ubuntu 里面一些 Python 库
- Python 的一些高级特性
- odoo里面Python的一些简便写法