在 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.