定义函数只会为其命名,指定要包含在函数中的参数,并构成代码块。
一旦确定了函数的基本结构,即可通过从另一个函数或直接从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