In fact, Python module and module installation and other programming languages, such as: NodeJs, Reactjs the same, but they use the package management tool is not the same, Python with Pip, and node with NPM
Python module
The Python language, like many other programming languages (Nodejs, Reactjs), also has a lot of built-in modules that we can use just to introduce them.
SYS module
# #编写模块# #sys‘a test module‘_author = ‘yehui‘;import sys;def test(): args = sys.argv; if len(args) == 1: print("hello world!"); elif len(args) == 2: print("hello, %s!" % args[1]); else: print("too many arguments");if __name__ == ‘main‘: test();print(test());# hello world!
The SYS module has a argv variable that stores all parameters of the command line with the list, argv has at least one parameter, and the first parameter is always a. py file.
Scope
In a module, some of our variables and functions want to be used only within the function, then we can use the _ prefix to implement. A function or variable similar to _XXX is non-public.
Installing third-party modules
In Python, installing a third-party module is done through the Package management tool Pip , which is similar to Node's package management tool, NMP. In general, third-party libraries are registered on the official Python pypi.python.org website.
Common installation command format:
pip install xxx #相应模板的名称
Install common modules
You can directly use Anaconda(official website [https://www.anaconda.com/download/] To download the Gul installation package), a Python-based data processing and scientific computing platform, It has built in a number of very useful third-party libraries, we installed anaconda, it is equivalent to the dozens of third-party modules to install automatically, very easy to use.
Summarize
This part of the individual feel that there is nothing to summarize, and the same as other programming languages. The source of study is also the website Python tutorial of Liu Xuefeng teacher.
Python module and module installation