|
|
 |
 |
 |
 |
Python Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
example: 40286 -> 68204
Hi all, Is there a fuction that reverse the digits of a number? Many thanks, Shihpin Lin
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
Brian, Thanks! I will try it when I come home,
> > Shihpin Lin > This does it: > >>>> def reversed_int(i): > > ... return int(''.join(reversed(str(i)))) > > ... > >>>> reversed_int(12345) > > 54321 > Best, > Brian vdB
On Jun 3, 5:23 pm, Shihpin <Shihpin.@gmail.com> wrote: > Hi all, > Is there a fuction that reverse the digits of a number? > Many thanks, > Shihpin Lin
One can use int, str and a slice: print int(str(40286)[::-1]) -- Hope this helps, Steven
Thanks Steven, I will try to decipher that. Shihpin On 6 4 , 1:45, attn.steven.@gmail.com wrote:
> On Jun 3, 5:23 pm, Shihpin <Shihpin. @gmail.com> wrote: > > Is there a fuction that reverse the digits of a number? > One can use int, str and a slice: > print int(str(40286)[::-1]) > -- > Hope this helps, > Steven
|
 |
 |
 |
 |
|