Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

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,

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:

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc