Here, we will figure out how to compose a capacity in the Python programming language that profits the whole number acquired by switching the digits of the given whole number?
Capacity is the assortment of code that makes to play out a particular errand and work for different sources of info. At the point when we need to do similar work after
an interim then the capacity diminishes the length of code, time multifaceted nature, and so forth. Here, we will compose a capacity in Python that takes as information a positive number which will be given by the client and returns
the whole number acquired by turning around the digits. Prior to going to tackle this issue, we will get familiar with a tad about the capacity and how to make it in the Python programming language.
Syntax to make capacity 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 capacity square starts with the “def” watchword and “function_name“. In the enclosure, it might have a contention or not.
Presently, how about we begin to make a capacity in Python that profits the whole number acquired by turning around the digits.
Prior to going to take care of the above issue, expect the name of capacity is the reverse(n) and the parameter n which worth will be given by the client.
The capacity reverse(n) restores the whole number acquired by turning around the digits in n.
Program:
# function definition that will return
# reverse string/digits
def reverse(n):
# to convert the integer value into string
s=str(n)
p=s[::-1]
return p
# now, input an integer number
num = int(input('Enter a positive value: '))
# Calling the function and printing the result
print('The reverse integer:',reverse(num))
Output:
RUN 1:
Enter a positive value: 123456
The reverse integer: 654321
RUN 2:
Enter a positive value: 362435
The reverse integer: 534263
In Python, [::- 1] is utilized to turn around the list, string, and so on. It is a property of slicing of the rundown.