Python语言精要
#有个知识点
import matplotlib.pyplot as plt
from pylab import *
img = plt.imread('二元运算符.png')
imshow(img)
#有个知识点
import matplotlib.pyplot as plt
from pylab import *
img = plt.imread('标准的Python标量类型.png')
imshow(img)
zip
seq1 = ['foo','bar','baz']
seq2 = ['one','two','three']
zip(seq1,seq2)
<zip at 0x2a680ce5f80>
pitchers = [('Nolan','Ryan'),('Roger','Clemens'),
('Schilling','Curt')]
first_names,last_names = zip(*pitchers)
first_names
('Nolan', 'Roger', 'Schilling')
last_names
('Ryan', 'Clemens', 'Curt')
#有个知识点
import matplotlib.pyplot as plt
from pylab import *
img = plt.imread('Python的集合运算.png')
imshow(img)
列表推导式:
[expr for val in collection if condition]
字典推导式:
{key-expr: value_expr for value in collection if condition}
集合推导式:
{expr for value in collection if condition}
匿名(lambda)函数
#根据字符串不同字母的数量对其进行排序
strings = ['foo','card','bar','aaaa','abab']
strings.sort(key=lambda x:len(set(list(x))))
strings
['aaaa', 'foo', 'abab', 'bar', 'card']
#有个知识点
import matplotlib.pyplot as plt
from pylab import *
img = plt.imread('Python的文件模式.png')
imshow(img)
#有个知识点
import matplotlib.pyplot as plt
from pylab import *
img = plt.imread('重要的Python文件方法或属性.png')
imshow(img)