Section VIII: time and random module

definition:

Python code module is a collection of a group, other modules, may also be used with other modules.

Key:

1, the module name and not the name of the module that comes with the same, or will his priority call that module, since (except time, sys module) is to find the time to find the module in accordance with the path sys.path (), you can use the import under the name of the module to test whether there is a conflict

2, the main program added if __name __ = '__ main__' contents can be prevented others implement their own modules in the module to call their own when non-modular section

3, using tissue package module can be prevented from conflicting modules

 

Built-in Module time:

from time import time

time () Gets the timestamp

localtime () to get local time (East eight districts, eight hours behind Greenwich Mean Time) (default to convert a timestamp into struct_tiem)

例如:time.struct_time(tm_year=2020, tm_mon=4, tm_mday=10, tm_hour=1, tm_min=16, tm_sec=23, tm_wday=4, tm_yday=101, tm_isdst=0)

gmtime, () Gets UTC time (default timestamp converted struct_tiem)

例如:time.struct_time(tm_year=2020, tm_mon=4, tm_mday=9, tm_hour=17, tm_min=16, tm_sec=51, tm_wday=3, tm_yday=100, tm_isdst=0)

gmtime (). tm_hour Gets a value struct_time in time, localtime () also applies

 

 

Timeshift:

time.mktime (time.gmtime ()) to convert the format into a timestamp struct_time

time.stiftime () converts into formatted strc_time time, for example: print (time.strftime ( '% Y-% m-% d% H:% M:% S', time.gmtime ()))

the time.strptime () is converted into the time format strac_time example: print (time.strptime ( '2020-04-09 16:53:03', '% Y-% m-% d% H:% M:% S '))

that time.asctime () Default struct_time converted into a format Fri Apr 10 00:47:11 2020

time.ctime () The default timestamp converted format Fri Apr 10 00:47:11 2020

 

 

 

Key Time Module datetime:

import datetime

print (datetime.datetime.now ()) the most humane of the most common time format, 2020-04-1000: 58: 04.055228

 

random module:

from random imprt *

random () Default random floating point number between 0-1

Integer between randint (1,3) random 1-3, comprising 3

Integer between randrange (1,3) random 1-3, excluding 3

([2,3]) a random element in the choice list

sample ([1.2.3.4.5], 2) a random list of two random numbers

Floating between uniform (1,3) random 1-3

Operations: Generate a random digit codes 

  

Guess you like

Origin www.cnblogs.com/sxdpython/p/12670826.html