October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Python Operators and Conditionals: Route a Fictional Airport Check-in

Use a fictional airport desk to learn how Python operators test values and how if, elif, and else route execution.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python operators turn values into comparisons and logical tests; if, elif, and else use those tests to choose which indented code runs. The examples below use a fictional check-in desk to show how the pieces fit together—not to describe real airline rules.

Start with values and comparisons

Imagine a small program tracking a fictional traveler. The variables below are invented teaching data; bag_limit is not an actual baggage allowance.

As an Amazon Associate I earn from qualifying purchases.

has_ticket = True
bags = 1
bag_limit = 2
seat = "12A"

Comparison operators produce a truth value that can guide a decision:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Operator Example What it checks
== seat == "12A" Whether the values are equal.
< bags < bag_limit Whether the left value is less than the right.
>= bags >= 1 Whether the left value is greater than or equal to the right.

Use == to compare values in ordinary checks. A single = is assignment, which binds a value to a variable; it is not the equality test to use in an if condition.

Route execution with if, elif, and else

An if statement evaluates its condition and runs the indented block when that condition is true. You can add zero or more elif branches (“else if,” as the Python tutorial explains) and an optional else fallback. Python checks the branches in order and runs the first matching block.

if not has_ticket:
    message = "Check the booking"
elif bags > bag_limit:
    message = "Review the bag allowance"
else:
    message = "Continue to the next example"

All three outcomes and the bag limit are invented for the lesson. The else branch means only that neither earlier condition matched; it does not represent an airline decision. Each block must be indented consistently. See the Python tutorial’s control-flow section.

Combine conditions with and and or

Use and when both conditions must be true, and or when either condition is sufficient. For example, a made-up program might require both a ticket and bags within its invented limit:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
can_continue = has_ticket and bags <= bag_limit

Here, the left side checks the ticket flag; the right side compares the bag count with the fictional limit. A hypothetical alternate route could accept either a ticket or a staff override:

has_override = False
can_enter_example = has_ticket or has_override

These are programming examples, not check-in criteria. Parentheses help show intended grouping when combining operators:

ready_for_example = has_ticket and (seat == "12A" or seat == "12B")

This means the ticket must be present and the seat must match either of the two example strings. Without parentheses, precedence still determines how an expression is grouped, but explicit grouping can make the logic easier to read.

Understand truth values and short-circuiting

In a condition, False, None, numeric zero, and empty strings or containers are false. Other values are true unless an object defines its own truth value. This means a condition can test a value directly, not just the result of a comparison:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
seat = "12A"
if seat:
    message = "A seat value was supplied"

and and or evaluate operands from left to right and short-circuit when the result is already determined. They can return one of their operands—not necessarily the Boolean values True or False. For instance, has_ticket and seat returns the first false operand if there is one; otherwise it returns seat.

Short-circuiting is useful when the second test depends on the first being satisfied:

if seat and seat.startswith("12"):
    message = "Seat is in the example row"

If seat is empty, the left side is false and Python does not call startswith. The second operation is therefore protected from being called on an empty value.

Choose membership, identity, and ordering checks for their purpose

Not every comparison asks whether two values are equal. Python also provides membership tests and identity tests; they answer different questions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • in and not in check whether a value is present in a container. For example, seat in {"12A", "12B"} asks whether the seat string is one of those set members.
  • is and is not check whether two references point to the same object. A common appropriate use is value is None; do not substitute is for value equality such as seat == "12A".
  • Ordering operators such as < and >= compare orderable values, such as numbers. They are not a replacement for equality checks.

For a range, Python supports chained comparisons. 0 <= age < 18 means 0 <= age and age < 18; the middle expression is evaluated once.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Read precedence without guessing

Python groups these operators from tightest to loosest: comparisons first, then not, then and, then or. Thus a < b and c groups as (a < b) and c. Add parentheses when they clarify the intended decision, especially when mixing and and or. The Python language reference documents truth-value testing, Boolean evaluation, comparisons, and precedence; the tutorial also covers conditions and comparison types.

Practice with the official tutorial

The official Python tutorial is freely available online and is aimed at programmers new to Python. Try changing one value at a time in the examples and predicting which branch runs before executing the code.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.