- 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.
- Qt 5 and OpenCV 4 Computer Vision Projects
- CMDB分步構(gòu)建指南
- 零基礎(chǔ)PHP學(xué)習(xí)筆記
- 簡單高效LATEX
- Instant Zepto.js
- JavaScript+jQuery開發(fā)實(shí)戰(zhàn)
- Java編程指南:基礎(chǔ)知識(shí)、類庫應(yīng)用及案例設(shè)計(jì)
- Magento 1.8 Development Cookbook
- 用戶體驗(yàn)增長:數(shù)字化·智能化·綠色化
- C#應(yīng)用程序設(shè)計(jì)教程
- ASP.NET程序開發(fā)范例寶典
- Building Serverless Architectures
- 零代碼實(shí)戰(zhàn):企業(yè)級(jí)應(yīng)用搭建與案例詳解
- 深入實(shí)踐DDD:以DSL驅(qū)動(dòng)復(fù)雜軟件開發(fā)
- Python第三方庫開發(fā)應(yīng)用實(shí)戰(zhàn)