How to call Python custom module?

WBOY
Release: 2023-05-08 21:25:06
forward
1746 people have browsed it

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)
Copy after login

Create another Python file in the same directory, call module1 .py this module:

import module1
module1.fun1(20,30)
Copy after login

What does python mean

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template