How to call a function in Python?

python

#1

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.


#2

@Manish,

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
else:
    return b

Function Call

message() #Function call without arguments

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

Hope this helps!

Regards,
Imran


#3

Thanks a lot Imran :slight_smile: