In this post we will where to use the keyword 'in' on our python scripts and get things done. Lets get started,
IN[1]
friends = ["Prathap", "Darwin", "Delli"]
print("Prathap" in friends)
OUT[1]
Using the keyword in we can find out if an element is available in a list. From above we can see, there is a list named friends which contains element "Prathap" on validating it with keyword in inside print function True has been returned.
IN[2]
games_played = {"GOD 4", "Anthem", "Uncharted 4"}
user_game = input("Enter the Game you played : ")
print(user_game in games_played)
OUT[2]
Similarly we can do the same not only on list but can be done on both tuples and sets as well.
IN[3]
Name = "Prathap Dominicsavio"
print("Prathap" in Name)
OUT[3]
Finally we can also find whether a substring or character is available in string. From above a variable named Name has string "Prathap Dominicsavio" when we use in keyword to search substring "Prathap" it returns True.