- Mastering Python Networking
- Eric Chou
- 154字
- 2021-07-02 21:42:33
Python functions
Most of the time when you find yourself reusing some pieces of code, you should break up the code into a self-contained chunk as functions. This practice allows for better modularity, is easier to maintain, and allows for code reuse. Python functions are defined using the def keyword with the function name, followed by the function parameters. The body of the function consists of Python statements that are to be executed. At the end of the function, you can choose to return a value to the function caller, or by default, it will return the None object if you do not specify a return value:
def name(parameter1, parameter2):
statements
return value
We will see a lot more examples of function in the following chapters, so here is a quick example:
>>> def subtract(a, b):
... c = a - b
... return c
...
>>> result = subtract(10, 5)
>>> result
5
>>>
推薦閱讀
- Learning Python Web Penetration Testing
- 基于粒計算模型的圖像處理
- Android項目開發入門教程
- 網站構建技術
- PHP+Ajax+jQuery網站開發項目式教程
- Kotlin開發教程(全2冊)
- Java圖像處理:基于OpenCV與JVM
- JavaScript程序設計:基礎·PHP·XML
- Android Development Tools for Eclipse
- 貫通Tomcat開發
- 深入淺出Python數據分析
- Wearable:Tech Projects with the Raspberry Pi Zero
- Android開發進階實戰:拓展與提升
- Android 5從入門到精通
- Python Django Web從入門到項目實戰(視頻版)