在 Python 中呼叫函式
定義一個函式僅會給它指定一個名稱、指明函式中即將包含的引數,以及構造程式碼塊。
函式的基本結構一旦最終確定,就可以透過從另一個函式中或直接從 Python 提示符呼叫來執行它。以下是呼叫 printme() 函式的示例 −
#!/usr/bin/python
# Function definition is here
def printme( str ):
"This prints a passed string into this function"
print str
return;
# Now you can call printme function
printme("I'm first call to user defined function!")
printme("Again second call to the same function")輸出
執行以上程式碼後,將生成以下結果 −
I'm first call to user defined function! Again second call to the same function
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP