- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 166字
- 2021-07-02 14:00:30
Modules
Modules are just files that contain Python statements and definitions. A file that contains Python code (for example, sample.py) is called a module and its module name would be sample. Using modules, we can break larger programs into small and organized ones. An important feature of a module is re-usability. Instead of copying the definitions of the most used functions in different programs, you can define them in the module and just import them whenever needed.
Let's create a module and import it. We will create two scripts: sample.py and add.py. We will import a sample module in our add.py. Now, save the following code as sample.py. Let's take a look with the following example:
sample.py
def addition(num1, num2):
result = num1 + num2
return result
Here, we have defined a addition() function inside a module named sample. The function takes in two numbers and returns their sum. Now we have created a module. You can import this in any Python program.
- Spring 5.0 Microservices(Second Edition)
- 技術(shù)領(lǐng)導(dǎo)力:程序員如何才能帶團(tuán)隊(duì)
- Effective Python Penetration Testing
- SQL Server 2016數(shù)據(jù)庫(kù)應(yīng)用與開發(fā)習(xí)題解答與上機(jī)指導(dǎo)
- 快速念咒:MySQL入門指南與進(jìn)階實(shí)戰(zhàn)
- 深入RabbitMQ
- Python機(jī)器學(xué)習(xí)算法: 原理、實(shí)現(xiàn)與案例
- Building Microservices with .NET Core
- Machine Learning With Go
- Hands-On Neural Network Programming with C#
- JQuery風(fēng)暴:完美用戶體驗(yàn)
- Greenplum構(gòu)建實(shí)時(shí)數(shù)據(jù)倉(cāng)庫(kù)實(shí)踐
- Swift High Performance
- Elastix Unified Communications Server Cookbook
- Learning Zimbra Server Essentials