CPython,用 C 和 Python 编写的,将 Python 代码编译成字节码,同时使用编译器和解释器
JPython,在 Java 平台上运行 Python 代码
Brython,在浏览器上运行,类似于 JavaScript
MicroPython,适用于微控制器
5、运行慢但仍然是最常用的语言之一
6、一切皆引用(reference)
7、在火星上运行(Running On Mars),这一点是什么鬼哦
You will get surprised to know that python is running on mars. Texting robots on Mars using python to send images to the earth. It uses request module to communicate with the API on mars.
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!
1、lambda
mean = lambda x : sum(x) / len(x)
x = [5, 10, 15, 20]
print(mean(x))
x = [True, True, False]
if any(x):
print("At least one True")
if all(x):
print("None False")
if any(x) and not all(x):
print("At least one True and one False")
2、bashplotlib
可以在控制台画图,一个三方库
3、Collections
我知道这个库里面有很多好用的模块,比如我用过的有 namedtuple 和 defaultdict
from collections import OrderedDict, Counter
# memorize the order of adding keys
x = OrderedDict(a=1, b=2, c=3)
# count the frequency of each character
y = Counter("Hello World!")
4、dir
这个在前面的某一篇文章中介绍过,用来查看 Python对象的内部属性
5、emoji
用来展示 emoji 的三方库
from emoji import emojize
print(emojize(": thumbs_up:"))
6、__future__
这个库里面也有很多好用的模块
7、geopy
从一系列不同的地理编码服务中提取 api 来获得该地点的完整地址、其纬度、经度,甚至其海拔高度
from geopy import GoogleV3
place = "37 Tavistock Pl, Saint Pancras, London"
location = GoogleV3().geocode(place)
print(location.address)
print(location.location)
8、howdoi
有意思的命令行工具,使用 pip 安装
$ howdoi vertical alignn css
$ howdoi for loop in java
$ howdoi undo commits in git
import sh
sh.pwd()
sh.mkdir('new_folder')
sh.touch('new_file.txt')
sh.whoami()
sh.echo('This is great!')
20、类型注解
Python 3.5+
from typing import List
Vector = List[float]
Matrix = List[Vector]
def addMatrix(a: Matrix, b: Matrix) -> Matrix:
result = []
for i, row in enumerate(a):
result_row = []
for j, col in enumerate(row):
result_row + = [a[i][j] + b[i][j]]
result + = [result_row]
return result
x = [[1.0, 0.0], [0.0, 1.0]]
y = [[2.0, 1.0], [0.0, -2.0]]
z = addMatrix(x, y)