By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

example: 40286 -> 68204

P: n/a
Hi all,

Is there a fuction that reverse the digits of a number?

Many thanks,

Shihpin Lin

Jun 4 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Jun 4 '07 #2

P: n/a
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

Jun 4 '07 #3

P: n/a
On Jun 3, 5:23 pm, Shihpin <Shihpin....@gmail.comwrote:
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

Jun 4 '07 #4

P: n/a
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.comwrote:
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

Jun 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.