Python › Programming Fundamentals

Numbers, booleans, and operators

4 min read Beginner 5 sections

Numbers and booleans are how your scripts do maths and make decisions. You won’t write much heavy arithmetic in security work, but you’ll constantly compare values — “is this status code 200?”, “did I find more than zero results?” — and that’s what this lesson is really about.

You'll learn to

  • Do arithmetic, including the two division forms
  • Compare values to produce True/False
  • Combine conditions with and / or / not

Arithmetic

8080 + 1        # 8081   addition
10 - 3          # 7      subtraction
4 * 8           # 32     multiplication
10 / 3          # 3.333  division (always gives a float)
10 // 3         # 3      integer division (floor — drops the remainder)
10 % 3          # 1      modulo (the remainder)
2 ** 10         # 1024   exponent (2 to the power of 10)

Most of these are obvious, but two are worth a pause. // is integer division — it divides and throws away the remainder. % (modulo) gives you just the remainder, and it’s surprisingly useful: it’s how you do “every Nth” logic, like printing progress every 100 requests.

# Print a status update every 100 items in a long loop:
if count % 100 == 0:
    print(f"...processed {count}")

Comparisons make booleans

Every comparison returns True or False:

status == 200   # equal?         (note: TWO equals signs)
status != 200   # not equal?
count > 5       # greater than
count >= 5      # greater than or equal
count < 5       # less than
count <= 5      # less than or equal

These are the conditions you’ll test all day: if status == 200, if len(results) > 0.

Logical operators combine conditions

is_up and is_authenticated    # True only if BOTH are true
is_admin or is_owner          # True if EITHER is true
not blocked                   # flips True to False and vice versa

These let you express real logic: “if the host is up and we’re authenticated, proceed.” You’ll combine them with comparisons constantly:

if status == 200 and "admin" in response_text:
    print("found an accessible admin page")

Checkpoint

What's the difference between 10 / 3 and 10 // 3 in Python?

Try it yourself

In the REPL, set status = 403. Write a single condition that is True when the status is either 401 or 403 (both mean “auth-related”). Hint: use == twice joined with or.

Summary

Arithmetic includes two division forms — / (float) and // (integer) — plus % (modulo) for remainders and “every Nth” logic. Comparisons (==, !=, >, <, etc.) produce booleans. Logical operators and, or, not combine conditions into the filters that drive your scripts. Never confuse = (assign) with == (compare).

Key takeaways

  • // is integer division; % gives the remainder (great for progress logic).
  • Comparisons return True/False.
  • and / or / not combine conditions — the heart of triage logic.
  • = assigns, == compares. Don’t mix them up.

Quick quiz

Next, the container types — lists, tuples, sets, and dictionaries — which hold your targets, dedupe your results, and shape every request.

Was this lesson helpful?