1. List comparison function cmp
>>> a = [1,2,3,4]>>> b = [1,2,3,4,5]>>> c = [1,2,3,4]>>> cmp (A, B) -1>>> CMP (a , c) 0
2, list parsing, code simplification
>>> a[1, 2, 3, 4]>>> d = []>>> for i in a: ... D.append (i + 2) ... >>> d[3, 4, 5, 6]>>> e = []>>> E = [i + 2 for i in A]>>> e[3, 4, 5, 6]
3. Dictionary creation
>>> d = Dict.fromkeys ([' Today ', ' Tomorrow '],20) >>> d{' tomorrow ': +, ' Today ': 20}
4. Set particularity
>>> s = {1,2,3,4}>>> t = {4,3,6}>>> sset ([1, 2, 3, 4]) >>> Tset ([3, 4, 6]) >>> T | S # and set Set ([1, 2, 3, 4, 6]) >>> T & S #交集set ([3, 4]) >>> T-S #差集 in T is not set in S ([[6]) >>& Gt t ^ s #对称差集 value not present in TS set ([1, 2, 6])
5. Function-Type programming
①map >>> a [1, 2, 3, 4] >>> n = map (lambda x:x+2,a) >>> n [3, 4, 5, 6]
#注意: Requires n = List (n) ②reduce >>>reduce (Lambda x,y:x*y, Range (1,8)) in 3.x #上述命令相当于 > >> s = 1 >>> for I in Range (1,8): ... s = S * I ... >>> s 5040 #注意: python3.x requires from fuctools import reduce ③filter >>> b = Filter ( Lambda x:x > 5 and X < 8, range (Ten)) >>> b [6, 7] #上述函数比for和while循环效率高
6. python2.x using Print ()
From __future___ import print_function
7. python2.x Division Change
>>> from __future__ Import Division
>>> 3/2
1.5
>>> 3//2
1
Python Learning (v): Easy to forget knowledge points