Calling a Function in Python


Defining a function only gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code.

Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is the example to call printme() function −

 Live Demo

#!/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")

Output

When the above code is executed, it produces the following result −

I'm first call to user defined function!
Again second call to the same function

Updated on: 29-Jan-2020

248 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements