Articles β†’ Python β†’ Functions in python

Functions in python






What is function?





Example




# this is the function definition
def HelloWorld():
    print("Hello World")
    return


# this is the function call
HelloWorld()




Picture showing the output of the HelloWorld function in python

Click to Enlarge




Passing parameter in function




# this is the function definition
def HelloWorld(name):
    print("Hello ", name)
    return


# this is the function call
HelloWorld("gyan")




Picture showing the output of a function with input parameters

Click to Enlarge


Returning value from function




def WelcomeMessage(name):
    name = "Hello" + name
    return name

welcomeMessage = WelcomeMessage("gyan")
print(welcomeMessage)




Picture showing the output of a function with return statement

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, February 28, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250