Introduction to Python related modules

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

  1. calendar module

• 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>)

  1. datetime module

• 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

  1. time module

• 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

Introduction to Python related modules
01. Introduction to Python
Introduction to Python
python introduction
Python from entry to proficiency (2): Introduction to Python
Introduction to Podman
How to introduce third-party modules in Python
Introduction to Python commonly used visualization libraries
How to install third-party modules in Python
How to add custom modules in Python
How to view installed modules in python
Centos 6.4 python 2.6 upgrade to 2.7
Python PyQt5 finishing introduction
Centos 6.4 python 2.6 upgrade to 2.7
python download new modules
09. Common modules of Python3
How to understand the introduction of packages in Python
Solution to python alignment error
Python introduction and environment installation
CentOS upgrade python2 to pyth
Python code to find bugs (2)
Python code to find bugs(7)
How to comment python code
Python code to find bugs(4)
Python code to find bugs (3)
Python code to find bugs(9)
How to learn python quickly
How to uninstall python plugin
Python code to find bugs(6)
Python code to find bugs (1)
Python code to find bugs(8)
3 ways to encrypt Python files
How to understand python objects
Python code to find bugs(5)
How to use python tuples
python functions, classes, modules, packages
Python Data Science: Related Analysis
Collection of Python Common Modules
Python| function using recursion to solve
Method steps to increase python font
python how to view webpage code
How to use python thread pool
Use python to query Oracle database
[Introduction to redis] Install redis under Centos
Use C++ to write Python3 extensions
How to write python configuration file
Python novice learns to raise usage
Use python to achieve stepwise regression
How to wrap in python code
Python implements 126 mailboxes to send mail
Using Python to implement multiple clipboards
How to omit parentheses in Python
How to install Python 3.8 on CentOS 8
Python example to calculate IV value
How to install Python 3.8 on Ubuntu 18.04
How to write classes in python
How to filter numbers in python
Centos6.7 comes with python upgrade to
How to read Excel in Python
How to install Python on CentOS 8
How to solve python dict garbled