Advertisement



< Prev
Next >



Python - Functions





A function in a program contains a block of statements that are performing some particular task. As a program grows, the need for creating functions, where each function is performing a specific task becomes prominent. To understand functions, we should learn about how to:





Let's suppose a program has two functions, one is called at the beginning of the program to notify that program has started and the other one is called to notify when the program has finished its routine work. Let's see how we do this.

# Python - defining and calling multiple functions 



# welcome() function is defined
def welcome():	
    print('Welcome to the program!')


# goodbye() function is defined
def goodbye():	
	print('The program is going to end. Goodbye!')


# welcome() function is called at the beginning of the program
welcome()    

a,b = 10,20
result = a * b
print('Result of 10 x 20 is : ', result)

# goodbye() function is called at the end of the program
goodbye()


Output-


Welcome to the program!
Result of 10 x 20 is :  200
The program is going to end. Goodbye!


We could even pass values to a function when it is called. For doing this, we will have to first define a function with formal arguments within the parenthesis(). For more on this, please continue with our next article.


Please share this article -





< Prev
Next >
< Python User-Defined Exception
Python functions with arguments >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement