1. Python references extension modules
• import <module>[as <alias>]: Import functions and other names in the module into the current program, "namespace" namespace, reference method——<module>.<name>
• dir (<name>) function: lists the attributes of the name
• help(<name>) function: display the reference manual
• from <module>import <name>: part of the name of the imported module
2. Time related modules
• Several functions and classes related to calendar can generate calendar in text form
• calendar.calendar(<year>)
• calendar.month(<year>,<month>), returns a multi-line string
• calendar.isleap(<year>), to distinguish leap years
• calendar.prmonth(<year>,<month>)
• calendar.prcal(<year>)
• There are 4 main categories: date processing year, month and day, time processing hour, minute, second, millisecond, datetime processing date plus time, timedelta processing period (time interval)
• Common functions/methods: datetime.date.today(), datetime.datetime.now(), datetime.datetime.isoformat()
• Subtracting two times is timedelta
• The current time represented by time.time() floating point numbers: the number of seconds since 1970-1-1 0:0:0
•Time.struct_time structured time class: time.localtime(<epoch time>)->structure, time.gmtime(<epoch time>)->structure, time.mktime(<structured time>)->epoch time
• time.strftime(<format>) represents formatted output (structured) time
• time.strptime(<string>,<format>) identifies the string according to the format and returns the time
3. Arithmetic Module
• math: commonly used arithmetic functions, trigonometric functions, power exponents, etc.
• cmath: math function that supports complex numbers
• Decimal: Decimal fixed point, decimal decimal, there is no longer floating point error
• fractions: rational numbers, proportions, fractional calculations
• random: random number.
random.randint(a,b),random.randrange(start,stop,step) ,
random.choice(seq),random.sample(seq,n)。
• statistics: some statistical functions.
Average: mean, median: median, standard deviation: stdev/pstdev.
Fourth, persistence: shelve
• Save any data object to a file
• Similar to dictionary access, readable and writable: import shelve, f = shelve.open(<file name>), f[key] = value, value = f[key], del f[key], f.close( ).
Recommended Posts