On Fri, 23 Jul 2010 11:22:54 pm 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?
str1.find("o") will return the index of the first "o", or -1 if not found. str1.rfind("o") does the same, but searches from the right instead of the left. str1.index("o") is like find, but it raises an exception instead of returning -1. Naturally there is a rindex as well. -- Steven D'Aprano _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor