0
how to reverse the order of a integer?
8 Answers
+ 3
By using the method ( reverse)
My_List= ["1","2","3"]
My_List.reverse()
print(My_List)
>>>
['3','2','1']
>>>
+ 1
There is no builtin method for this functionality but you can make a function of your own and call it whenever you need it.
+ 1
def reverseint(x):
s =str(x)
s = s[::-1]
return int(s)
0
but what about integers?if i want to reverse those integers?
0
x = 123
s =str(x)
s = s[::-1]
x = int(s)
print(x)
>>> 321
Is that what you mean?
0
ya exactly!
do we have some sort of a function to directly convert it?
0
but how?
0
number=int(input("enter a number: "))
while(number !=0):
rem=number%10
print(rem)
number=number//10
rem.reverse()
print(rem)
here if we input 456
so we'll get
6
5
4
simply we are separating the digits
but i want the reverse order of that
like this
4
5
6
so what can I do??