On Tue, Mar 15, 2016 at 11:26 AM, <[email protected]> wrote:
> In Python is it possible to comparison-equate a variable to a List, Tupple,
> or Set and have it return True if the contents of the variable matches an
> element in the List, Tupple, or Set.
>
> E.g.
>
> x = "apple"
>
> x-list = ["apple", "banana", "peach"]
>
> If x == x-list:
> print('Comparison is True')
> else:
> print('Comparison is False')
Yep! What you're looking for is the "membership" operator. It's spelled "in":
>>> x = "apple"
>>> x_list = ["apple", "banana", "peach"]
>>>
>>> if x in x_list:
... print("That is a fruit.")
... else:
... print("That is not a fruit.")
...
That is a fruit.
>>> x = "jump"
>>> if x in x_list:
... print("That is a fruit.")
... else:
... print("You must be Chell.")
...
You must be Chell.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list