What is the difference among: if...in, if...not in, else?

I got a few questions that were wrong regarding this with some of the later python beginning modules and a lot of the intermediate modules in the Data Science track.

  1. if...in do something for me if x is in y, ie, True
>>> if 1 in [1, 2, 3]:
   ...:     print("Yes 1 is in the list")

Yes 1 is in the list
  1. if...not in do something for me if x is not in y, ie, True
>>> if 4 not in [1, 2, 3]:
   ...:     print("Yes 4 is not in list")

Yes 4 is not in list
  1. else do something for me if the above results in a False
>>> if 4 in [1, 2, 3]:
    ...:     print("Yes 4 is in list")
    ...: else:
    ...:     print("No, 4 is not in list")

No, 4 is not in list

More to uncover:

1 Like