Python最大的优点之一就是语法简洁,好的代码就像伪代码一样,干净、整洁、一目了然。要写出 Pythonic(优雅的、地道的、整洁的)代码,需要多看多学大牛们写的代码,github 上有很多非常优秀的源代码值得阅读,比如:requests、flask、tornado,下面列举一些常见的Pythonic写法。
程序必须先让人读懂,然后才能让计算机执行。
“Programs must be written for people to read, and only incidentally for machines to execute.”
1、交换赋值

2、Unpacking

3、使用操作符in

4、字符串操作

5、字典键值列表

6、字典键值判断

7、字典 get 和 setdefault 方法

8、判断真伪

9、遍历列表以及索引

10、列表推导

11、列表推导-嵌套

12、循环嵌套

13、尽量使用生成器代替列表

小编推荐一个学Python的学习裙【 二二七,四三五,四五零 】,无论你是大牛还是小白,是想转行还是想入行都可以来了解一起进步一起学习!裙内有开发工具,很多干货和技术资料分享!希望新手少走弯路
14、中间结果尽量使用imap/ifilter代替map/filter

15、使用any/all函数

16、属性(property)

17、使用 with 处理文件打开

18、使用 with 忽视异常(仅限Python 3)

19、使用 with 处理加锁

涨姿势了吗?