Labs ICT
🎓 SIWES/IT Login

Operators

1 min read | Python Tutorial
🎓

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

Arithmetic Operators

Python provides all the standard arithmetic operators you'd expect from a calculator, plus a few extras like floor division and exponentiation.

x = 15
y = 4
print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x // y)
print(x % y)
print(x ** y)

Comparison Operators

Comparison operators compare values and return True or False. They're the building blocks of decision-making in code.

a = 10
b = 20
print(a == b)
print(a != b)
print(a < b)
print(a > b)
print(a <= b)
print(a >= b)

Logical Operators

and, or, and not let you combine multiple conditions into more complex checks.

x = 5
print(x > 0 and x < 10)
print(x > 0 or x > 10)
print(not x > 0)

Identity Operators

is and is not check if two variables refer to the same object in memory, not just if they have the same value.

a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a is c)
print(a is b)
print(a is not b)