A function is the collection of code that creates to perform a specific task and work for various inputs. When we have to do the same work after an interval then the function reduces the length of code, time complexity, etc. Here, we will write a function in Python that takes as input a positive integer which will be given by the user and returns the integer obtained by reversing the digits. Before going to solve this problem, we will learn a little bit about the function and how to create it in the Python programming language.
Syntax to create a function in Python:
# definition
def function_name(parameters):
''' function statement that specifies the work
of the function i.e body of function.'''
return(expression)
# function calling
print(functionname(parameters)
The function block begins with the "def" keyword and "function_name". In the parenthesis, it may have an argument or not.
Now, let's start to create a function in Python that returns the integer obtained by reversing the digits. Before going to solve the above problem, assume the name of a function is the reverse(n) and the parameter n which value will be provided by the user. The function reverse(n) returns the integer obtained by reversing the digits in n.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer