在 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