1. Users can generate custom modules for calling. A custom module is a Python file. The Python file created when writing code is equivalent to a module.
2. The called module should be placed in the same directory of the current Python file as much as possible, otherwise the folder should be declared as importable when importing.
Example
Create a new Python file named module1, the code is as follows:
def fun1(a,b) : #实现a+b并输出结果 print(a+b)
Create another Python file in the same directory, call module1 .py this module:
import module1 module1.fun1(20,30)
Python is a cross-platform, interpreted, compiled, interactive and object-oriented scripting language, its original design It is used to write automated scripts. As the version is constantly updated and new features are added, it is often used to develop independent projects and large-scale projects.
The above is the detailed content of How to call Python custom module?. For more information, please follow other related articles on the PHP Chinese website!