1

I wanna know if there is a way to check for two objects without using the -or- operator, or using it but without the declaration. Here's the example

if x == y or x == z:

Instead of that, I would like to do something like

if x == y or z:

Is there any way to do that? Maybe using an array? Thanks for the help

Ben Moreau
  • 29
  • 1
  • 5
  • 1
    Is there a specific reason why `if x == y or x == z:` is not good enough? – dm2 Aug 03 '21 at 17:16
  • 1
    I guess you can do `if x in (y, z):` – gen_Eric Aug 03 '21 at 17:18
  • Hey dm2, yes there is a reason, I wanna make a group of users who will have the authority to do something, but instead of adding them one by one, I would like to just make a group of them, and then calling them – Ben Moreau Aug 03 '21 at 17:21
  • Alright Rocket, thanks (that just helped me a lot for another issue I was having) – Ben Moreau Aug 03 '21 at 17:22

2 Answers2

1

You cold try doing something like:

if x in [z, y]:
ferranllor
  • 11
  • 3
1

I don't see any reason not to use if x == y or x == z:, but if you have multiple values to compare, then the code just gets longer, and in that case, in operator becomes handy to use:

if a in {w,x,y,z}: # equivalent to a==w or a==x or a==y or a==z
    # rest of the code
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45