Python common function/Method records
One, Python's random module:
Import module:
Import Random
1. Random () Method:
As shown above, this function returns a random floating-point number of "0,1"(left-closing right-open) .
to control a range of "Min,max", you can return a random floating-point number between 20~30 with min+ (max-min) *random.random () , as shown below:
2. Choice (seq) method:
The method returns a random element from the sequence seq:
3. Randint (A, B) method:
The method randomly randomly generates an integer between A~b, as follows:
4. Shuffle (seq) method:
Shuffle has the meaning of "scrambling", as the name implies, the function of this method is to randomly disrupt the elements of a sequence (seq) as shown in:
5. Sample (Seq,n) method:
The method is returned from the sequence (seq), randomly selecting the number of N, as shown in:
Second, commonly used advanced functions
1. The map function, based on the provided function, maps the specified sequence, returning the mapped result:
Grammar:
Map (function,iterable,...)
The examples are as follows:
2. The filter function filters out elements that do not meet the criteria and returns a new list of eligible elements:
Grammar:
Filter (function,iterable,...)
The examples are as follows:
3. A zip function that accepts an iterative object and converts it into a tuple (packaged).
Grammar:
Zip (iterable,iterable,....)
The examples are as follows:
----------------------------------------Pause, Subsequent update-----------------------------------------------------------
Python common function records