Experience of Python learning Week4

本文介绍了Python中List Comprehensions的使用,并对比了生成器和迭代器的优势。讨论了生成器如何节省内存空间,以及如何通过简单的语法改变实现从列表到生成器的转换。此外还介绍了装饰器的应用及JSON与pickle序列化的区别。

 

First of all , I have learnt the List Comprehensions in python , it’s quite simple , like this :

 

But however, due to the limit of storage usage , if we creat a list of 10,000,000 elements , it’ll take so much space , and if we only need the top several elements , the elements behind it will be wasted. So people with clever mind come up with a good idea , it’s the Generator. Just make “[]” become “()”,then it comes to a success. But generator only has ‘__next()__’ function , but you can use for loop to fetch the data . One thing  very important is that ‘yield’ sentence could make Concurrent operation in one operation line.

After that is the Iterator , everything that is the object of FOR is Iterable ,  and that could be the object of next() is Iterator.

Then is the Decorator: you can use it to add new functions to you old function.

Json&pickle serialization: 1.json : string — > python data type 2.pickle: python special data type —> python data type.

Built-in functions: …

转载于:https://www.cnblogs.com/pathToFuture/p/7443821.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值