Python Basics

Python how to check if list contains element?

In python, we can check if a list contains certain element. For this “in” keyword is helpful.

Example

selected_candidates=[“rahul”,”ajay”,”vijay”]

#check if raju is present in the list

if “raju” in selected_candidates:

print(“Raju has been selected for the job”)

else:

print(“Raju has been disqualified for the job”)

Output:

Raju has been disqualified for the job.