0% found this document useful (0 votes)
3 views5 pages

Grade 9 Operators in Python

Uploaded by

ehtsalman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Grade 9 Operators in Python

Uploaded by

ehtsalman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

OPERATORS IN PYTHON

Python operators are special symbols or keywords that perform operations on


one or more operands (values or variables). They are categorized into several
types based on the operations they perform:
 Arithmetic Operators:
Used for mathematical calculations.
 + (Addition)
 - (Subtraction)
 * (Multiplication)
 / (Division)
 % (Modulo - returns the remainder of a division)
 ** (Exponentiation - raises the first operand to the power of the second)
 //(Floor Division - returns the integer part of the division)
 Assignment Operators:
Used to assign values to variables. They often combine an arithmetic operation with
assignment.
 = (Assignment)
 += (Add and assign)
 -= (Subtract and assign)
 *= (Multiply and assign)
 /= (Divide and assign)
 %= (Modulo and assign)
 **= (Exponentiation and assign)
 //=(Floor division and assign)
 Comparison (Relational) Operators:
Used to compare two values and return a Boolean result ( True or False).
 == (Equal to)
 != (Not equal to)
 > (Greater than)
 < (Less than)
 >= (Greater than or equal to)
 <=(Less than or equal to)
 Logical Operators:
Used to combine conditional statements and evaluate overall truth values.
 and (Logical AND)
 or (Logical OR)
 not (Logical NOT)
 Bitwise Operators:
Used to perform operations on the binary representation (bits) of integers.
 & (Bitwise AND)
 | (Bitwise OR)
 ^ (Bitwise XOR)
 ~ (Bitwise NOT)
 << (Left shift)
 >> (Right shift)
 Identity Operators:
Used to check if two variables refer to the exact same object in memory.
 is (Is the same object)
 is not (Is not the same object)
 Membership Operators:
Used to test if a value is present within a sequence (like a string, list, or tuple).
 in (Is a member of)

 not in (Is not a member of)


🔹 Conditional and Control Statements in
Python
Python provides different statements to control the flow of a program. These mainly include:

1. Conditional Statements
Used to make decisions in the program.

if statement
num = 10
if num > 0:
print("Positive number")

if-else statement
num = -5
if num >= 0:
print("Positive number")
else:
print("Negative number")

if-elif-else statement
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")

Nested if statement
num = 15
if num > 0:
if num % 2 == 0:
print("Positive Even Number")
else:
print("Positive Odd Number")

2. Loop Control Statements


It is used to apply whenever we need to repeat a block of code.

for loop
for i in range(1, 6):
print(i) # Prints numbers from 1 to 5

while loop
count = 1
while count <= 5:
print(count)
count += 1

3. Loop Control Keywords


Used inside loops to change normal execution flow.

 break → exits loop immediately

for i in range(1, 10):


if i == 5:
break
print(i) # Prints 1 2 3 4

 continue → skips current iteration, continues with next

for i in range(1, 6):


if i == 3:
continue
print(i) # Prints 1 2 4 5

 pass → does nothing, used as a placeholder

for i in range(1, 6):


if i == 3:
pass # Placeholder
print(i) # Prints 1 2 3 4 5
✅ Summary Table

Statement Purpose
if Executes a block if condition is True
if-else Executes one block if condition True, another if False
if-elif Multiple conditions
for Loop with a range or sequence
while Loop until condition becomes False
break Exit loop immediately
continue Skip current iteration
pass Do nothing (placeholder)

You might also like