The symbols that let you calculate, compare, combine conditions, and check data — and exactly where each one shows up in real code.
You write if salary = 50000: expecting to check if salary equals 50000, but Python throws a syntax error. Why? Because = ASSIGNS a value, while == COMPARES two values — two completely different operators that look almost identical.
An Operator is a symbol that tells Python to perform a specific action on one or more values — add them, compare them, combine conditions, or check a relationship. Every operator belongs to a category based on WHAT KIND of action it performs.
Confusing similar-looking operators (like = vs ==, or and vs &) is one of the most common sources of bugs for freshers — and later, one of the most common PySpark interview "gotcha" questions too. Getting comfortable with each operator category now saves you from confusing errors for the rest of your career.
You're calculating a student's average score across 3 tests, and separately, checking whether a total number of items can be evenly split into boxes of 10.
Simple Answer: Arithmetic operators do standard math — but Python has two operators freshers often haven't seen before: // (floor division, drops the decimal) and % (modulus, gives you the REMAINDER, not the division result).
a = 17 b = 5 print(a + b) # 22 addition print(a - b) # 12 subtraction print(a * b) # 85 multiplication print(a / b) # 3.4 division (always returns a float) print(a // b) # 3 floor division (drops the decimal) print(a % b) # 2 modulus (the REMAINDER of the division) print(a ** b) # 1419857 exponent (17 to the power of 5)
% (modulus) is used constantly in real code — checking if a number is even (n % 2 == 0), splitting data into evenly-sized batches, or building pagination logic ("show 10 records per page"). It shows up far more often than freshers expect.
/ → normal division, always returns a float// → floor division, rounds DOWN to the nearest whole number% → modulus, gives you the REMAINDER left overYou need to check if a student's score qualifies as a "Pass" (score is greater than or equal to 40) — the program needs a True/False answer to decide what happens next.
Simple Answer: Comparison operators compare two values and always produce a Boolean (True or False) — never a number or text. This is what powers every if statement and filter condition you'll ever write.
score = 42 print(score == 40) # False is equal to? print(score != 40) # True is NOT equal to? print(score > 40) # True greater than? print(score >= 40) # True greater than or equal to? print(score < 40) # False less than?
Every filter you write in Pandas (df[df['age'] > 25]) or PySpark (df.filter(col('salary') > 50000)) is built entirely on comparison operators underneath — this is a direct, everyday extension of what you're learning right now.
== compares (two equals signs); = assigns (one equals sign) — never mix these up!= means "not equal to"You want to allow registration only if the user is 18 OR OLDER, AND has agreed to the terms and conditions. That's TWO separate conditions that both need checking together.
Simple Answer: Logical operators combine multiple True/False conditions into one final answer. and requires BOTH to be true, or requires AT LEAST ONE to be true, and not flips a True/False result.
age = 20 agreed_terms = True can_register = (age >= 18) and agreed_terms print(can_register) # True (both conditions are true) is_weekend = False is_holiday = True day_off = is_weekend or is_holiday print(day_off) # True (at least one is true) print(not is_weekend) # True (flips False to True)
Real business rules almost never depend on just ONE condition — "active AND premium AND not flagged for fraud" is a typical real filter. Note: in PySpark, you'll use & and | instead of and/or when combining DataFrame column conditions — a very common fresher mix-up.
and → ALL conditions must be trueor → AT LEAST ONE condition must be truenot → flips True to False, or False to TrueYou're keeping a running total of items in a shopping cart. Writing total = total + new_item_price every single time works, but Python gives you a shorter way to say the exact same thing.
Simple Answer: = stores a value into a variable. The shorthand versions (+=, -=, etc.) update a variable based on its OWN current value, without retyping the variable name twice.
total = 100 total += 50 # same as: total = total + 50 -> 150 total -= 20 # same as: total = total - 20 -> 130 total *= 2 # same as: total = total * 2 -> 260 total //= 3 # same as: total = total // 3 -> 86 print(total)
You'll use += constantly inside loops — counting rows processed, accumulating totals during data cleaning, or tracking a running count of errors found in a pipeline. It's one of the most-used shortcuts in everyday code.
= → assigns a value (one equals sign)+=, -=, *=, /= → update the variable using its own current valueYou have a list of blocked email domains, and before allowing a signup, you need to quickly check: "is this user's email domain in the blocked list?"
Simple Answer: in checks if a value EXISTS inside a list, string, dictionary, or set. not in checks the opposite — that it does NOT exist.
blocked_domains = ["spam.com", "fake.com"] email_domain = "gmail.com" print(email_domain in blocked_domains) # False print(email_domain not in blocked_domains) # True # also works on strings directly: print("gmail" in email_domain) # True (substring check)
This is exactly the pattern behind data validation checks — "is this category in my list of allowed categories," "does this column name exist in my schema." Combined with a set (from the Data Types class), membership checks become extremely fast even on large data.
in → checks if a value exists inside a collectionnot in → checks that it does NOT existYou check if a variable is empty using middle_name == None, and it works fine — but Python style guides insist you should ALWAYS write middle_name is None instead. What's the actual difference?
Simple Answer: == checks if two values are EQUAL. is checks if two variables point to the EXACT SAME OBJECT in memory — a stricter, different kind of check. For checking None specifically, Python convention always uses is, because there's only ever ONE None object in the entire program.
middle_name = None print(middle_name is None) # True - this is the correct, recommended way print(middle_name == None) # True - works, but not the recommended style list_a = [1, 2, 3] list_b = [1, 2, 3] print(list_a == list_b) # True - same VALUES print(list_a is list_b) # False - different OBJECTS in memory, even though values match
This exact confusion (== vs is) is a classic Python interview question used to test if you truly understand how Python stores data, not just surface-level syntax. Always use is None / is not None in real code — it's both the correct convention and slightly faster.
== → do these have the same VALUE?is → are these literally the SAME OBJECT in memory?is None, never == NoneYou're combining two filter conditions in a PySpark DataFrame: df.filter((col("age") > 18) & (col("active") == True)). That & symbol looks like the logical "and," but it's technically a bitwise operator being reused here.
Simple Answer: Bitwise operators work on the individual BINARY BITS of numbers. As a fresher, you won't use these for raw binary math often — but you WILL see & and | constantly in Pandas/PySpark for combining column conditions, instead of and/or.
# plain Python booleans - use 'and' / 'or' print(True and False) # False # Pandas/PySpark column conditions - must use & / | instead # df.filter((col("age") > 18) & (col("active") == True))
This is directly relevant to your PySpark work — using and/or instead of &/| when combining DataFrame filter conditions is one of the most common errors freshers hit when moving from plain Python into PySpark.
and / or& / | instead, always wrapped in parenthesesUse this table for a fast recall of every operator category covered today.
| Category | Symbols | Returns | Common Real-World Use |
|---|---|---|---|
| Arithmetic | + - * / // % ** |
Number | Calculations, running totals, pagination |
| Comparison | == != > < >= <= |
Boolean | Filters, validation, if-conditions |
| Logical | and or not |
Boolean | Combining multiple business rules |
| Assignment | = += -= *= /= |
— | Storing and updating variables, loops |
| Membership | in, not in |
Boolean | Checking if a value exists in a collection |
| Identity | is, is not |
Boolean | Checking for None, exact object identity |
| Bitwise | & | ^ ~ << >> |
Number/Boolean | Combining Pandas/PySpark filter conditions |
A fresher writes a PySpark filter using and the same way they would in plain Python, and gets a confusing error. This single mix-up is one of the most common early PySpark bugs, and understanding WHY it happens (not just memorizing the fix) is what actually prevents it long-term.
| Context | Use This | Not This | Why |
|---|---|---|---|
| Plain Python booleans | and, or |
&, | |
Logical operators are designed for single True/False values |
| Pandas / PySpark column conditions | &, | |
and, or |
DataFrame conditions work on WHOLE columns of values at once, which and/or can't handle correctly |
# Correct: plain Python condition age = 20 active = True if age > 18 and active: print("Allowed") # Correct: PySpark DataFrame condition (always use & with parentheses) # df.filter((col("age") > 18) & (col("active") == True))
and / or& / |, always wrapped in parenthesesOperators are the verbs of programming — Arithmetic does math, Comparison checks relationships, Logical combines conditions, Assignment stores/updates values, Membership checks existence, Identity checks object sameness, and Bitwise works at the binary level (and doubles as PySpark's condition-combining syntax). Recognizing which category an operator belongs to — and not confusing similar-looking ones like =/== or and/& — is one of the fastest ways to write clean, bug-free code from day one.