example: 40286 -> 68204

Brian van den Broek broek at cc.umanitoba.ca
Sun Jun 3 20:31:35 EDT 2007


Shihpin said unto the world upon 06/03/2007 08:23 PM:
> Hi all,
> 
> Is there a fuction that reverse the digits of a number?
> 
> Many thanks,
> 
> Shihpin Lin
> 

This does it:

>>>> def reversed_int(i):
> ...     return int(''.join(reversed(str(i))))
> ... 
>>>> reversed_int(12345)
> 54321
>>>> 
> 

Best,

Brian vdB



More information about the Python-list mailing list