1.divmod (a, b) returns a tuple of the quotient and remainder of (a // b, a% b)
2.all () is used to determine all the elements can be given iteration parameters in the whether iterable are TRUE, if it is to return True, otherwise False
If all elements of iterable not 0, '', False or iterable is empty, all (iterable) Returns True
3.enumerate()
seasons = ['Spring', 'Summer', 'Fall', 'Winter'] list(enumerate(seasons)) [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')] list(enumerate(seasons, start=1)) # 下标从 1 开始 [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
4.int () function is used to convert a string or an integer number
int ( '12', 16) # if base parameters, then, to input 12 as a string of 12 hexadecimal 18 is int ( '0xA', 16) 10 int ( '10',. 8) . 8
ASCII value 5.ord () to which a character (a string of length 1) as a parameter and returns the corresponding
>>>ord('a') 97
6.any () to determine whether not empty, false, returns True
>>> any (( 'a', 'b', '', 'd')) # tuple tuple, there is an empty element True >>> the any ((0, '', False)) Element # group tuple, all the elements being 0, '', to false False
Value 7.eval () function is used to perform a string expression, and returns the expression
s= (34) print(eval("s*3"))
102
8.pow()
pow (x, y) is equivalent to Y * X: 4 ** 2 # 16 result 4 ** 2.5 # result is 32.0 POW (X, Y, Z) is equivalent to Y% Z ** X: . 4 * 2.5% * # 3 results 2.0 #pow (X, y, z) z X when this parameter is not present, y is not limited whether to float, and when the third parameter is used to ensure that only the first two parameters It can be an integer >>> POW (11.2,3.2) 2277.7060352240815 >>> POW (11.2,3.2,2) # result of an error Traceback (MOST recent results Last Call): File "<stdin>", Line 1, in <Module> TypeError : POW () 3rd All arguments The argument are not allowed The unless integers >>>
9.exec execution
with open('test1.py','r') as f: exec(f.read()
10.issubclass determines whether B is a subclass of A
A class: Pass class B (A): #B inherited from A, B is a subclass of A Pass Print (issubclass (B, A))
A method 11.super () is used to call the parent class (super class)
class A: def add(self, x): y = x+1 print(y) class B(A): def add(self, x): super().add(x) b = B() b.add(2) # 3
12. iter generated iterator
>>>lst = [1, 2, 3] >>> for i in iter(lst): ... print(i) ... 1 2 3
13.tuple list argument group
14.filter filter
def is_odd(n): return n % 2 == 1 newlist = filter(is_odd, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) print(newlist)
15.chr and ord
print(chr(43)) print(ord("b")) + 98
16.callable method for detecting whether an object can be called, may be called an object refers to the ability to use () method call parentheses.
>>> callable(1) False >>> 1()
17.lacals ()
def func(): a=1 b=2 print(locals()) func() # {'a': 1, 'b': 2}
18.reduce () function will be tired parameter elements in a sequence. reduce () function has been removed from the global name space, it is now placed in the module in functools
from functools import reduce def add(x,y): return x + y print (reduce(add, range(1, 101)))
19.frozenset () returns a frozen collection, the collection can not add or remove any elements after freeze
a = frozenset (range (10) ) # generates a new set of immutable >>> A frozenset ([0,. 1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9])
Why frozen collections (ie, the set of immutable ) it? Because the set of relationships, there are elements in the collection is another set of circumstances, but the general collection (set) itself is variable , so its instances will not be placed another set of elements (set must It is immutable type).
Therefore, to provide a set of functions frozenset immutable, when the set is not changed when it meets the requirements as a set of elements , it can be set up in another.