[Tutor] position of an element in list:

Christian Witts cwitts at compuscan.co.za
Fri Jul 23 15:38:20 CEST 2010

On 23/07/2010 15:22, Vineeth Rakesh wrote:
> Hello all,
> How to return the position of a character in a string. Say I have str1 
> = "welcome to the world" if i want to return the position of the first 
> occurrence of "o" how to do it?
> Thanks
> Vin
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Strings have a function called index, which take a string argument which 
is what you're looking for.  So you can do str1.index('o') which would 
return 4.

Kind Regards,
Christian Witts

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100723/41c82346/attachment.html>

More information about the Tutor mailing list