在 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

更新於:2020 年 1 月 29 日

360 次瀏覽

開啟您的 事業

完成課程,獲得認證

開始
廣告
© . All rights reserved.