Operators are special symbols used to perform operations on variables and values. Python has a wide range of built-in operators grouped into several categories such as arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators.
True or False.and, or, and not.+ – Addition- – Subtraction* – Multiplication/ – Division (returns float)% – Modulus (remainder)** – Exponentiation// – Floor division (truncates decimal part)
a = 10
b = 3
print(a + b) # 13
print(a ** b) # 1000
=, +=, -=, *=, /=, //=, %=, **=
x = 5
x += 3 # same as x = x + 3
print(x) # 8
== – equal to!= – not equal to> – greater than< – less than>= – greater than or equal to<= – less than or equal to
a = 10
b = 5
print(a == b) # False
print(a > b) # True
and – returns True if both conditions are Trueor – returns True if at least one condition is Truenot – inverts a boolean value
x = 5
print(x > 3 and x < 10) # True
print(not(x > 3)) # False
is – True if both variables refer to the same objectis not – True if they do not refer to the same object
a = [1, 2]
b = a
c = [1, 2]
print(a is b) # True
print(a is c) # False
in – checks if a value exists in a sequencenot in – checks if a value does not exist in a sequence
mylist = [1, 2, 3]
print(2 in mylist) # True
print(5 not in mylist) # True
& – bitwise AND| – bitwise OR^ – bitwise XOR~ – bitwise NOT<< – left shift>> – right shift
a = 5 # 0101
b = 3 # 0011
print(a & b) # 1
print(a | b) # 7
a + b with a = 10 and b = 3 gives 13 because it adds two numbers.a ** b calculates 10 raised to the power 3, which is 1000.a == b returns False because 10 is not equal to 5.a is b is True only when both variables refer to the exact same object in memory.2 in mylist is True when 2 exists in the list [1, 2, 3].() to ensure the correct order of operations in complex expressions.// truncates the decimal part; it does not round.type() when mixing integers and floats to avoid unexpected behavior.== to compare values and is to compare object identity.+, -, *, /, %, **, //).is and is not.in and not in.and / or and print whether the overall expression is True or False.