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()

輸出

執行上述程式碼後,會返回以下結果 −

Traceback (most recent call last):
File "test.py", line 11, in <module>
printme();
TypeError: printme() takes exactly 1 argument (0 given)

更新時間: 30-Jan-2020

7K+ 瀏覽次數

啟動你的職業生涯

透過完成課程獲取認證

開始學習
廣告
© . All rights reserved.