r/learnpython • u/Brick_Bronze8 • Nov 07 '24
How do I compare 2 variables, where one variable contains 5 values?
This is basically what it boils down to:
How do I see if variable x is equal to variable y where y contains 5 numbers? (For example 1,2,3,4,5)
6
u/shiftybyte Nov 07 '24
Does x also contain 5 numbers? Then you can do that with equals sign:
>>> x = [1,2,3,4,5]
>>> y = [1,2,3,4,5]
>>> x == y
TrueIs x a single number? then it can't be equal to 5 numbers now can it?
Perhaps you want to ask if x is contained in a list of 5 numbers?
>>> x = 5
>>> y = [1,2,3,4,5]
>>> x in y
True1
2
3
1
u/VipeholmsCola Nov 07 '24
You need to be more specific.
If the first variable can be either of the other 5 values, then check 'if a in (1,2,3,4,5)'
Otherwise, you need to make sure that the first metric is comparable to the second.
1
12
u/DangerDinks Nov 07 '24
Do you mean that you want to see if variable x is contained within variable y?
If so, you can do