Python Logical Operators (the fun stuff!!)
About this video
Episode six of his Python series teaches logical operators through a running coffee-shop scenario: a robot barista bouncer script that already rejects a character named Ben if he is evil must now also handle Patricia and Loki. The ‘or’ operator extends one if statement so the check passes when the name matches any of the listed names, and he fixes the rejection message to use the entered name variable instead of hard-coding Ben. He then adds a twist: an evil visitor who has done enough good deeds that day can still enter. A new input asks for the number of good deeds, wrapped in int() because input returns a string by default, and the ‘and’ operator is added so rejection requires both being evil and having done fewer than four good deeds; a test with seven good deeds is admitted while two is rejected. Only that one if statement is allowed to change. The second half introduces ’not’, showing that if not name == ‘Ben’ reverses the logic, then connects it to Booleans: comparisons such as me == ‘NetworkChuck’ return True or False, type() reveals the bool class, and applying not flips the result. He closes by noting the more common alternative, the != comparison operator, which expresses ‘does not equal’ more readably than not, and points learners to extra challenge labs for repetition.
Key takeaways
- Use ‘or’ when any one condition being true is enough, e.g. checking whether a name equals Ben, Patricia or Loki in a single if statement.
- Use ‘and’ when all conditions must be true together, e.g. evil status is yes and good deeds is less than four before someone is rejected.
- Numeric input must be converted with int() because Python’s input function returns a string by default.
- ’not’ inverts a Boolean result, turning a true comparison false and vice versa, which can make code harder to read if overused.
- Comparisons produce Boolean True/False values, and the != operator is usually the clearer way to test that two values are not equal.
Episode details: published March 12, 2022 · 18:00 long. Summary written by Self Growth Videos from the episode itself. Business results and any income figures mentioned are NetworkChuck’s own claims, shared for education — they are not typical or guaranteed.
← Previous: forcing my wife to learn Linux in 24hrs · Next: my kids built a HACKING computer!! (i almost died) →
All NetworkChuck videos · NetworkChuck profile · NetworkChuck on YouTube





