python之禅
-
操作
1.在 jupyter中输入import this
-
内容及解释:
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
优美胜于丑陋
Explicit is better than implicit.
明确胜于模糊
Simple is better than complex.
简单胜于复杂
Complex is better than complicated.
复杂胜于混乱
Flat is better than nested.
扁平胜于嵌套
Sparse is better than dense.
稀疏胜于稠密
Readability counts.
可读性很重要
Special cases aren't special enough to break the rules.
Although practicality beats purity.
即便假借特例的实用性之名,也不可违背这些规则(这些规则至高无上)
Errors should never pass silently.
Unless explicitly silenced.
不要包容所有错误,除非你确定需要这样做(精准地捕获异常,不写except:pass风格的代码)
In the face of ambiguity, refuse the temptation to guess.
当存在多种可能,不要尝试去猜测
There should be one-- and preferably only one --obvious way to do it.
而是尽量找一种,最好是唯一一种明显的解决方案(如果不确定,就用穷举法)
Although that way may not be obvious at first unless you're Dutch.
虽然这并不容易,因为你不是 Python 之父(这里的Dutch是指
Now is better than never.
Although never is often better than *right* now.
做也许好过不做,但不假思索就动手还不如不做(动手之前要仔细思量)
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.
如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然(方案测评标准)
Namespaces are one honking great idea -- let's do more of those!
名称空间是一个非常好的主意--让我们来做更多的事情吧!
搭建Python环境
1.在Python官方网站下载对应版本的python安装程序(exe文件),安装时建议勾选“Add Python 3.6 to PATH”(将Python 3.6添加到PATH环境变量),并且将“pip”、“tcl/tk”、“Python test suite”等项全部勾选上。
注意:在Windows 7环境下安装时,需要先安装Service Pack 1补丁包(可以通过一些工具软件自动安装系统补丁的功能来安装)
从终端运行Python
打开命令提示符:win+r >> cmd
-
确认python版本
方法一:
python --version
方法二:
import sys
print(sys.version_info)
print(sys.version)
-
运行python程序
python hello.py
jupyter
-
安装环境
1.win+r >> cmd
2.python _m pip install ipython jupyter
-
使用jupyter
1.win+r >> cmd
2.jupyter notebook
PyCharm
1.首先要有java运行环境,这个环境要安装在C盘
2.在PyCharm官方网站下载安装包,安装时勾选64-bit,Do not import…
3.激活:需要激活码,lanyu提供免费激活码,但PyCharm每次会自动验证注册码,而注册码是动态的,那么用户每次使用时,都需要重新生成激活码,为了用户使用方便,我们可自行屏蔽验证注册码的网站,方法如下:
a.找到hosts文件,路径:C:\windows\system32\drivers\etc
b.在hosts文件中加入 代码:0.0.0.0 account.jetbrains.com