[Newbie]: How to find a specified digit in a number?

Steve Holden steve at holdenweb.com
Wed Nov 10 16:37:29 CET 2004


Mathias wrote:

> Hi everyone.
> 
> I'm making a little script which finds the right number from a couple of
> choices, but I need a function or script which finds a specified digit,
> eg. FindDigit(3579, 3) = 7.
> 
> Thanks in advance :-)

Modulo the error checking you should clearly do on the arguments:

 >>> def FindDigit(i, pos):
...   return str(i)[pos-1]
...
 >>> FindDigit(3579, 3)
'7'
 >>>

regards
  Steve
-- 
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119



More information about the Python-list mailing list