If Else Statements in Python // Python RIGHT NOW!! // EP 4

About this video

Episode 4 of the creator’s free ‘Python Right Now’ course teaches if/else statements and comparison operators through a running example: a robot barista/bouncer program for a coffee shop that must turn away a character named ’evil Ben.’ Working in a free browser-based lab, he adds if name == "Ben": after the program asks for a name, printing a rejection message when the condition is true. He then adds an else: branch containing the normal greeting, so the program does one thing when the statement is true and something else when it is false, instead of contradicting itself. He stresses that Python cares about indentation: code under an if or else must be indented, and removing that spacing produces an indentation error, though code editors help by auto-indenting. He practices with numeric examples such as if 4 > 3: printing ‘Yep, it’s true,’ then changing it to if 2 > 3: to see the else branch run. He covers the comparison operators — greater than, less than, less than or equal to, greater than or equal to, and double equals — and clarifies that a single = assigns a value to a variable while == evaluates whether a variable already equals something, noting that comparing an undefined variable raises an error. Finally, he solves a lab problem where Ben is rejected but the script still asks what coffee he wants: instead of nesting the whole remaining script under the else, he adds exit() after the rejection print so the program stops. He closes by promoting the sponsor ITProTV and additional practice labs.

Key takeaways

  • An if statement runs its indented block only when the condition evaluates to true
  • Adding else gives the program a different action to take when the condition is false
  • Python indentation is functional, not cosmetic — bad spacing causes indentation errors
  • Single = assigns a variable; double == compares whether two values are equal
  • Calling exit() after a branch lets a program stop instead of nesting the rest under else

Episode details: published February 7, 2022 · 14:19 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: i hired my replacement….kind of (the FUTURE of NetworkChuck) · Next: 2 cool (web) things to do in Linux // Linux for Hackers // EP 8 →

All NetworkChuck videos · NetworkChuck profile · NetworkChuck on YouTube

Sister brand · Vacation Club Promo

All-inclusive resort stays from $435

Qualified couples: promotional Mexico and Caribbean packages at real resorts. Short presentation during your stay — enjoy the rest of the trip.

Qualifications apply · presentation during stay · no purchase required

Subscribe YouTube Suggest