Python programming tutorials
Set up Python and run your first program. Then practice with number and string examples, sorting algorithms, and library functions.
Python core curriculum
Getting started
Decisions and loops
Functions and data
Files and projects
Reverse the digits of a number
class Sample:
def __init__(self):
pass
def reverseNumber(self):
input = 123
temp = input
output = 0
while(temp > 0):
r = temp % 10
temp = temp // 10
output = output * 10 + r
print("Original Number: " + str(input))
print("Reverse Number: " + str(output))
obj = Sample()
obj.reverseNumber()
Original Number: 123 Reverse Number: 321