Python continues!
Random
Includes functions that return random numbers.
This is like C + +, which produces pseudo-random numbers, not completely random numbers.
Some important functions in the random:
random () returns the random number of 0<n <=1 n getrandbits (n) returns n random bit (A, B) returns the random number n , a <=n <b Span class= "Hljs-title" >choice from sequence seq The returns any element shuffle (Seq[,random]) Specify the sequence in situ Span class= "Hljs-title" >seq sample (seq, n) Select
Simple and useful:
printrandom.uniform(10,20)printrandom.uniform(20,10)#----结果(不同机器上的结果不一样)#18.7356606526#12.5798298022randomrandom.random()0.85415370477785668random.uniform(110)5.4221167969800881
Time
The time module includes the following features:
Get current time, operation time, and date
Read time from string, format time as String
Some functions:
asctime([tuple]) 将时间元组转换为字符串localtime([secs]) 将秒数转为日期元组sleep(secs) 睡secs秒
Import Time if__name__==' __main__ ': Time.Sleep(1)Print "Clock1:%s"% Time. Clock () Time.Sleep(1)Print "Clock2:%s"% Time. Clock () Time.Sleep(1)Print "Clock3:%s"% Time. Clock ()
The following are the date formatting symbols:
%y Two-digit year representation (00-99)%Y A four-digit year representation (000-9999)%m Month (01-12)%D Day of the Month (0-31)%H 24-hour hours (0-23)%I 12-hour hours (01-12)%M Number of minutes (00=59)%S Seconds (00-59)%a Local Simplified Week name%A Local Full week name%B Locally Simplified month name%B Local Full month name%C Local corresponding date representation and time representation%J Day of the Year (001-366)%P equivalent of local a.m. or p.m.%U Number of weeks in the year (00-53) Sunday is the beginning of the week%W Week (0-6), Sunday for the beginning of the week%W Number of weeks in the year (00-53) Monday is the beginning of the week%x The local corresponding date representation%X Local corresponding time representation%Z The name of the current time zone %% number itself
Python basics-People's favorite standard library (random time)