0

how to reverse the order of a integer?

14th Aug 2016, 11:11 AM
Arshee Siddiqui
Arshee Siddiqui - avatar
8 Answers
+ 3
By using the method ( reverse) My_List= ["1","2","3"] My_List.reverse() print(My_List) >>> ['3','2','1'] >>>
14th Aug 2016, 11:51 AM
Abdulrahman Alshab
Abdulrahman Alshab - avatar
+ 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.
14th Aug 2016, 12:52 PM
Gershon Fosu
Gershon Fosu - avatar
+ 1
def reverseint(x): s =str(x) s = s[::-1] return int(s)
14th Aug 2016, 1:32 PM
Gershon Fosu
Gershon Fosu - avatar
0
but what about integers?if i want to reverse those integers?
14th Aug 2016, 12:03 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
0
x = 123 s =str(x) s = s[::-1] x = int(s) print(x) >>> 321 Is that what you mean?
14th Aug 2016, 12:45 PM
Gershon Fosu
Gershon Fosu - avatar
0
ya exactly! do we have some sort of a function to directly convert it?
14th Aug 2016, 12:50 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
0
but how?
14th Aug 2016, 12:55 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
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??
14th Aug 2016, 2:38 PM
Arshee Siddiqui
Arshee Siddiqui - avatar