1.python语法简单,容易理解,容易学习
2.跨平台,可以在windows,linux,mac os
3.可以做网站、爬虫、大数据处理
4.拥有强大的第三方库numpy,panda...
python 之禅
输入import this
>>>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.
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.
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之禅
翻译
备注
The Zen of Python, by Tim Peters
作者:Tim Peters
Beautiful is better than ugly.
优美胜于丑陋
python以编写优美的代码为目标
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.
虽然这并不容易,因为你不是dutch
dutch这里指的是python之父
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!
命名空间是一个很好的解决方案,我们需要多加利用
hello world
print('hello world')
hello world
print("hello world")
hello world
print("\"hello world\"")"hello world"print('\'hello world\'')'hello world'#合理的使用单双引号可以避免使用转义字符print("'hello world'")'hello world'print('"hello world"')"hello world"
python可以直接当作计算器来使用
2+352-112*362*365%21#2的3次方2**38#8开3次方8**(1/3)2.0import math
#math.pi是180°,math.pi/2是90°
math.sin(math.pi/2)
math.sin(math.pi/3)#向下取整,输出9
math.floor(9.599)#向上取整,输出10
math.ceil(9.599)#非math,四舍五入round(9.4)9round(9.5)10#format函数,增强的字符串格式化函数
a=5
b=6"a的值为:{},b的值为:{}".format(a,b)'a的值为:5,b的值为:6'