num = 654321
print(str(num)[::-1])
Output
654321
Using the string slicing concept, you can get reverse the string. ::-1 corresponds to start:stop:step. When you pass -1 as step, the start point goes to the end and stop at the front.
Source : https://www.programiz.com/python-programming/examples/reverse-a-number
No comments:
Post a Comment