beginnerBasics

Operators

Arithmetic, comparison, logical, assignment, and other operators.

01Arithmetic Operators

Used for basic mathematical operations.

Python
1a, b = 15, 4
2
3print(a + b) # 19 Addition
4print(a - b) # 11 Subtraction
5print(a * b) # 60 Multiplication
6print(a / b) # 3.75 Division
7print(a // b) # 3 Floor division
8print(a % b) # 3 Modulus
9print(a ** b) # 50625 Exponentiation
Output
19
11
60
3.75
3
3
50625

02Comparison Operators

Return True or False by comparing two values.

Python
1x, y = 10, 20
2
3print(x == y) # False
4print(x != y) # True
5print(x > y) # False
6print(x < y) # True
7print(x >= y) # False
8print(x <= y) # True
Output
False
True
False
True
False
True

03Logical Operators

Combine conditional statements using and, or, not.

Python
1a, b = True, False
2
3print(a and b) # False
4print(a or b) # True
5print(not a) # False
Output
False
True
False