Python Common Module 1. Random Module 1.1 Import module
Import Random
1.2 Random.random ()
Generate a random floating-point number from 0 to 1
1.3 Random.uniform (10,20)
Generates a random number between the pointing range, which is 10 to 20 (including 10 and 20, and where the positions are interchangeable)
1.4 Random.randint (A, B)
Generate an integer from A to B
1.5 Random.randrange ([Start],stop[,step])
Extracts the random number from the specified collection,
1.6 Random.choice (Sequence)
Gets a random element from the sequence that can make lists, strings, and so on.
With Np.random.choice (A,size=none.) Compared to only one
1.7 random.shuffle (X[,random])
X is a list that is used to disrupt the list
1.8 Random.sample (SEQNENCE,K)
Gets the fragment of the specified length from the development sequence.
1.9 Random.randint ()
Random integers
2. Time Module 2.1 Import module
Import time
2.2 Time.time ()
Returns the current time stamp
2.3 Time.localtime ()
Format timestamp as local time
2.4 Time.asctime (Time.localtime)
Accepts a time tuple and returns a readable string
2.5 time.ctime ()
Timestamp converted to asctime format, readable
2.6 Time.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ())
Formatting time tuples
2.7 Time.sleep ()
Process suspend time.
3. DateTime Module 3.1 Import module
Import datetime
3.2 Datetime.datetime.now ()
Gets the current datetime
3.3 Datetime.date.today ()
Get date of day, return 2018,4,8
3.4 Get tomorrow/the first n days
Datetime.date.today () +datatime.timedelta (Days=1)
3.5 Time difference between two datetime
Subtract back timestamp
3.6 Relationship Conversion 3.6.1 Datetime->string
Datetime.datetime.now (). Strftime ("%y-%m-%d%h:%m:%s")
3.6.2 String->datetime
Datetime.datetime.strptime ("2014-12-31 18:20:10", "%y-%m-%d%h:%m:%s")
3.6.3 Datetime->timestamp
now = Datetime.datetime.now ()
timestamp = Time.mktime (Now.timetuple ())
Timestamp
3.6.3 Timestamp->datetime
Datetime.datetime.fromtimestamp (1421077403.0)
3.6.4 Datetime->date
Datetime.datetime.now (). Date ()
3.6.5 Date->datetime
Today = Datetime.date.today ()
Datetime.datetime.combine (Today, Datetime.time ())
python+ Common Modules (2). MD