- 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.
- UI設計基礎培訓教程
- Extending Jenkins
- Java程序設計實戰教程
- INSTANT OpenCV Starter
- Java 9 Concurrency Cookbook(Second Edition)
- Visual Basic程序開發(學習筆記)
- Visual C++數字圖像模式識別技術詳解
- Hadoop+Spark大數據分析實戰
- Easy Web Development with WaveMaker
- CKA/CKAD應試教程:從Docker到Kubernetes完全攻略
- Xamarin.Forms Projects
- Mastering RStudio:Develop,Communicate,and Collaborate with R
- C# 8.0核心技術指南(原書第8版)
- Access 2010數據庫應用技術(第2版)
- Mastering Android Game Development