How to call a function in Python?



Q1 .What are the steps to call a function in Python? Please explain with an example.
Q2. Once the function is called, how can we pass the value to it? How will it get executed?

Thanks in advance.



Function Definition consist name, parameters (may or may not have) and blocks of statements as function body. Once the function definition is done, you can execute it by calling it from another function or directly from the Python prompt. This can be done using the name of the function with required arguments if it was there in function definition.

Let’s look at the example:

Function Definition

def message(): #Without parameters
    print 'Hi Welcome to Functions in Python' 

def check(a,b): #With parameters
if a>b:
    return a
    return b

Function Call

message() #Function call without arguments

c=check(a,b) #function call with arguments
print c

Hope this helps!



Thanks a lot Imran :slight_smile: