Python Functions - Part 1
In this article, I will be giving you an introduction to Python functions. What is a Python function A Python function is nothing but a block of code with a name. You can use its name to execute the code multiple times without having to write the code each time. It is similar to a method in Java except that it need not be defined within a class. How to define a function In order to write the code for a function, we first need to create a Python module. You can refer to this article to understand how to create a Python module. Let us assume that we have a module functions.py. Within this module, you can specify your first function. Consider the following code: def add(): num1 = int(input("Enter the first number:")) num2 = int(input("Enter the second number:")) result = num1+num2 print("sum is ",result) This code specifies a function add . You need to specify the keyword def before the function name. The function name is followed by empt