1.

Functions in Python

Answer»

Functions are used to well-organized our code and enhance code readability and reusability. In Python, a function is defined using the def keyword. A function can return some value, or not depending upon its use case. If it has to return a value, the return statement (which has been discussed) is used. The syntax of a python function is shown in the image below:

Example of a function:

# Function to return sum of two numbers
def getSum(a, b):
return a + b

# Function to print sum of 2 numbers
def printSum(a, b):
print(a + b)

print(getSum(5, 6))
printSum(5, 6)


Discussion

No Comment Found