💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**笔记名称:学点Python** `Tips: English is useful and necessary.` > 建议:笔记中所有代码,手动敲一遍,不要复制粘贴。 ## **适合人群** * 已经对Python基本语法有所了解,需要深入学习的入门者 * 适合Python开发者用作手册,随时查阅 * 具有其他编程语言基础的人,可通过本笔记快速上手Python ## **Contents** * Python 基础知识 * 数据类型 * 操作符 * 流程控制 * 函数 * 模块 * 面向对象编程 * 模式匹配与正则表达式 * 读写文件 * 异常处理 * 标准库概览 * Python 实战项目 * 控制台程序 * 实用小工具 * 处理 Excel * 处理 PDF 与 Word 文档 * 处理 CSV 文件和 JSON 数据 * 操作图像 * 网络爬虫 * 小游戏 * 微信/小程序 * Web 开发 * 数据分析 * 人工智能 ## **Author** * [随心而码](https://linjianming.com/) * 邮箱:admin@originspace.cn :-: 觉得有、用,打赏作者 | 微信 | 支付宝 | | --- | --- | | ![](https://box.kancloud.cn/3308d3dab7c6cdf286dfb95e793343b1_398x398.jpg) | ![](https://box.kancloud.cn/18981926604265368e006f0e1a00944b_320x314.jpg) | ## **The Zen of Python** 见 [https://www.python.org/dev/peps/pep-0020/](https://www.python.org/dev/peps/pep-0020/) ```python >>> import this ``` <table style="height: 713px; width: 644px;" border="0"><caption>Python 之禅 中英文对照</caption> <tbody> <tr style="background-color: #66cc33;"> <td><b>The Zen of Python, by Tim Peters</b></td> <td><b>Python之禅 by Tim Peters</b></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Beautiful is better than ugly.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">优美胜于丑陋(Python 以编写优美的代码为目标)</span></td> </tr> <tr style="background-color: #03c9fb;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Explicit is better than implicit.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">明了胜于晦涩(优美的代码应当是明了的,命名规范,风格相似)</span></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Simple is better than complex.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">简洁胜于复杂(优美的代码应当是简洁的,不要有复杂的内部实现)</span></td> </tr> <tr style="background-color: #03c9fb;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Complex is better than complicated.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">复杂胜于凌乱(如果复杂不可避免,那代码间也不能有难懂的关系,要保持接口简洁)</span></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Flat is better than nested.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;扁平胜于嵌套(优美的代码应当是扁平的,不能有太多的嵌套)</span></td> </tr> <tr style="background-color: #03c9fb;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Sparse is better than dense.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;间隔胜于紧凑(优美的代码有适当的间隔,不要奢望一行代码解决问题)</span></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Readability counts.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;可读性很重要(优美的代码是可读的)</span></td> </tr> <tr style="background-color: #03c9fb;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Special cases aren't special enough to break the rules.Although practicality beats purity.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;即便假借特例的实用性之名,也不可违背这些规则(这些规则至高无上)</span></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Errors should never pass silently.Unless explicitly silenced.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;不要包容所有错误,除非你确定需要这样做(精准地捕获异常,不写&nbsp;except:pass 风格的代码)</span></td> </tr> <tr style="background-color: #03c9fb;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">In the face of ambiguity, refuse the temptation to guess.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;当存在多种可能,不要尝试去猜测</span></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">There should be one-- and preferably only one --obvious way to do it.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;而是尽量找一种,最好是唯一一种明显的解决方案(如果不确定,就用穷举法)</span></td> </tr> <tr style="background-color: #03c9fb;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Although that way may not be obvious at first unless you're Dutch.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;虽然这并不容易,因为你不是&nbsp;Python 之父(这里的 Dutch 是指 Guido )</span></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Now is better than never.Although never is often better than *right* now.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;做也许好过不做,但不假思索就动手还不如不做(动手之前要细思量)</span></td> </tr> <tr style="background-color: #03c9fb;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然(方案测评标准)</span></td> </tr> <tr style="background-color: #cbe8ea;"> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">Namespaces are one honking great idea -- let's do more of those!</span></td> <td><span style="font-family: 'comic sans ms', sans-serif; font-size: 13px;">&nbsp;命名空间是一种绝妙的理念,我们应当多加利用(倡导与号召)</span></td> </tr> </tbody> </table> 作者:biyoulin 出处:**[http://www.cnblogs.com/biyoulin/](http://www.cnblogs.com/biyoulin/)**