📎 Referral Code:
📊 Dashboard Sign In
Navigation
🗺️
Live Classes
🗺️
Courses
🎬
Assignments
💡
Q & A
💡
My Profile
💡
Recruiter Board
Job Support
🎯
Interview Board
AI Tools
🌐
Project Explanation Agent
🛟
Support Works
📂 1. Python Basics To Advanced Level ⏱ 1.0h 📋 Video 3 of 21
📝 Class Notes
Class Documentation · Python Fundamentals

Python Data Operators

The symbols that let you calculate, compare, combine conditions, and check data — and exactly where each one shows up in real code.

01

What Is an Operator, and Why Does It Matter?

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.

Why You're Learning This

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.

Remember This
  • An operator performs an action on values (called "operands")
  • Python groups operators into categories: Arithmetic, Comparison, Logical, Assignment, Membership, Identity, Bitwise
  • Similar-looking operators (=, ==) do very different jobs — don't mix them up
02

Arithmetic Operators — Doing the Math

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).

arithmetic.py
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)
Where You'll Use This in Your Career

% (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.

Remember This
  • / → normal division, always returns a float
  • // → floor division, rounds DOWN to the nearest whole number
  • % → modulus, gives you the REMAINDER left over
03

Comparison (Relational) Operators — Comparing Two Values

You 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.

comparison.py
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?
Where You'll Use This in Your Career

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.

Remember This
  • == compares (two equals signs); = assigns (one equals sign) — never mix these up
  • Comparison always returns a Boolean, nothing else
  • != means "not equal to"
04

Logical Operators — Combining Multiple Conditions

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.

logical.py
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)
Where You'll Use This in Your Career

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.

Remember This
  • and → ALL conditions must be true
  • or → AT LEAST ONE condition must be true
  • not → flips True to False, or False to True
05

Assignment Operators — Storing and Updating Values

You'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.

assignment.py
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)
Where You'll Use This in Your Career

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.

Remember This
  • = → assigns a value (one equals sign)
  • +=, -=, *=, /= → update the variable using its own current value
  • These are just shortcuts — they don't do anything a longer line couldn't already do
06

Membership Operators — Checking If Something Exists Inside a Collection

You 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.

membership.py
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)
Where You'll Use This in Your Career

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.

Remember This
  • in → checks if a value exists inside a collection
  • not in → checks that it does NOT exist
  • Works on lists, strings (substring check), sets, dictionaries (checks keys)
07

Identity Operators — Same Value vs Same Object

You 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.

identity.py
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
Where You'll Use This in Your Career

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.

Remember This
  • == → do these have the same VALUE?
  • is → are these literally the SAME OBJECT in memory?
  • Rule: always use is None, never == None
08

Bitwise Operators — Working at the Binary Level

You'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.

bitwise.py
# 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))
Where You'll Use This in Your Career

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.

Remember This
  • Plain Python booleans → use and / or
  • Pandas/PySpark column conditions → use & / | instead, always wrapped in parentheses
  • Deep binary-level bitwise math is rare in everyday data engineering work
09

Quick Reference — All Operator Categories at a Glance

Use 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
10

"and/or" vs "&/|" — The Mix-Up That Trips Up Every Fresher

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
and_vs_ampersand.py
# 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))
Remember This
  • Working with single True/False values → and / or
  • Working with whole DataFrame columns → & / |, always wrapped in parentheses
  • This exact mistake is one of the top 3 errors freshers hit in their first PySpark assignment
Big Picture Takeaway

Operators 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.

June-08-2026:Morning 9:00AM - 10:00AM
June-08-2026:Morning 9:00AM - 10:00AM
0% done
5
6. AWS Core
1 videos