Operators
In
The in
operator is used to check if a value is present in a list, string, or other collection type. It returns true
if the value on the left side of the operator is found within the collection on the right side, and false
otherwise.
Example of how to use the in operator combined with if/else to verify if an item is present in a given list:
In this example, the in
operator checks if the string “Apple” is present in the list fruits
. Since “Apple” is in the list, the condition evaluates to true, and the message “Apple is in the fruits list.” will be displayed.