Last modified: Apr 04, 2026 By Alexander Williams
Python Symbols & Operators Guide for Beginners
Python uses symbols and operators to perform actions on data. They are the building blocks of logic and calculation.
Understanding them is your first step to writing powerful code. This guide explains all the essential types.
What Are Python Operators?
Operators are special symbols. They carry out operations on variables and values.
Think of them as the verbs in the language of Python. They tell the program what to do with the data.
Operators are grouped by their function. This makes them easier to learn and use.
Arithmetic Operators
Arithmetic operators handle basic math. They work with numbers.
You use them for addition, subtraction, and more. They form the core of numerical computation.
# Examples of Arithmetic Operators
a = 15
b = 4
print("Addition:", a + b) # Adds a and b
print("Subtraction:", a - b) # Subtracts b from a
print("Multiplication:", a * b) # Multiplies a and b
print("Division:", a / b) # Divides a by b (float result)
print("Floor Division:", a // b) # Divides and rounds down
print("Modulus:", a % b) # Remainder of a / b
print("Exponent:", a ** b) # a to the power of b
Addition: 19
Subtraction: 11
Multiplication: 60
Division: 3.75
Floor Division: 3
Modulus: 3
Exponent: 50625
Comparison Operators
Comparison operators compare two values. They return either True or False.
These are vital for making decisions in your code with if statements and loops.
# Examples of Comparison Operators
x = 10
y = 20
print("Equal to:", x == y) # False
print("Not equal to:", x != y) # True
print("Greater than:", x > y) # False
print("Less than:", x < y) # True
print("Greater/equal:", x >= y) # False
print("Less/equal:", x <= y) # True
Equal to: False
Not equal to: True
Greater than: False
Less than: True
Greater/equal: False
Less/equal: True
Logical Operators
Logical operators combine conditional statements. They are and, or, and not.
They allow you to test multiple conditions at once. This creates more complex logic flows.
# Examples of Logical Operators
is_weekend = True
is_sunny = False
print("Go out?", is_weekend and is_sunny) # True AND False = False
print("Stay in?", not is_sunny) # NOT False = True
print("Maybe?", is_weekend or is_sunny) # True OR False = True
Go out? False
Stay in? True
Maybe? True
Assignment Operators
Assignment operators assign values to variables. The basic one is the equals sign =.
Compound operators like += combine an operation with assignment. They make your code shorter.
# Examples of Assignment Operators
count = 5
print("Start:", count)
count += 2 # Same as count = count + 2
print("After +=", count)
count *= 3 # Same as count = count * 3
print("After *=", count)
count //= 4 # Same as count = count // 4
print("After //=", count)
Start: 5
After += 7
After *= 21
After //= 5
Identity and Membership Operators
Identity operators check if objects are the same. They use is and is not.
Membership operators test if a sequence contains a value. They use in and not in.
# Identity and Membership Examples
list_a = [1, 2, 3]
list_b = [1, 2, 3]
list_c = list_a
print("Identity (same object?):", list_a is list_c) # True
print("Identity (different?):", list_a is list_b) # False (different objects)
print("Value check:", list_a == list_b) # True (same values)
my_list = ['apple', 'banana', 'cherry']
print("Membership (in list):", 'banana' in my_list) # True
print("Membership (not in):", 'grape' not in my_list) # True
Identity (same object?): True
Identity (different?): False
Value check: True
Membership (in list): True
Membership (not in): True
Bitwise Operators
Bitwise operators work on numbers as binary bits. They are used in low-level programming.
Beginners use them less often. It's still good to know they exist for advanced tasks.
# Bitwise Operator Examples
a = 10 # Binary: 1010
b = 4 # Binary: 0100
print("AND (&):", a & b) # 0000 -> 0
print("OR (|):", a | b) # 1110 -> 14
print("XOR (^):", a ^ b) # 1110 -> 14
print("NOT (~a):", ~a) # Inverts bits
print("Left shift (a << 1):", a << 1) # 10100 -> 20
print("Right shift (a >> 1):", a >> 1) # 0101 -> 5
AND (&): 0
OR (|): 14
XOR (^): 14
NOT (~a): -11
Left shift (a << 1): 20
Right shift (a >> 1): 5
Operator Precedence
Python follows rules for which operator is calculated first. This is called precedence.
For example, multiplication happens before addition. You can use parentheses ( ) to change the order.
# Demonstrating Precedence
result = 5 + 2 * 3 # Multiplication first: 2*3=6, then 5+6
print("5 + 2 * 3 =", result)
result2 = (5 + 2) * 3 # Parentheses first: 5+2=7, then 7*3
print("(5 + 2) * 3 =", result2)
5 + 2 * 3 = 11
(5 + 2) * 3 = 21
Conclusion
Python symbols and operators are fundamental tools. They let you manipulate data and control logic.
Start with arithmetic and comparison operators. Then move to logical and assignment ones.
Practice with the examples provided. Soon, using these operators will become second nature.
They are the key to unlocking the full potential of the Python programming language.