Python find function for string search

You can search a character or even a string from a string through find function in Python. find function required one string parameter which you want to search. The find method returns the position value of the string which you are searching if it found in the string and if searched string does not found then it returns -1. The example of find method is mentioned below: Code



weekDaysString = "Sunday, Monday, Tuesday, Wednesday, Thursday"
result = weekDaysString.find("Tuesday")

if result != -1: 
        print("Your string is found at position -" . str(result))
else :
        print("Your string is not found.")

In above mentioned example we have a string variable with the name of weekDaysString and we make a search with find function and try to find the 'Tuesday' string, and store the result in result variable. We have also write a if conditional statement which shows a message that "Your string is found as position" if string found else if string does not found then shows a message that "Your string is not found".