UNIT 3 – PROGRAMMING FUNDAMENTALS 3.8 Operators CLASS XI COMPUTER SCIENCE – FBISE
Автор: Prep Quest
Загружено: 2026-01-28
Просмотров: 9
Описание:
WHAT IS AN OPERATOR
An operator is a symbol or keyword that tells the computer to perform a specific operation on one or more values called operands. Operators are used to perform calculations, compare values, test conditions, and manipulate data in a program.
Example
result = 10 plus 5
Here, plus is the operator and 10 and 5 are operands.
TYPES OF OPERATORS IN PYTHON (FBISE SYLLABUS)
According to the syllabus, the following operators are included:
Arithmetic operators
Bitwise operators
Membership operators
Comparison operators
Each type of operator has a specific role in programming.
3.8.1 ARITHMETIC OPERATORS
Arithmetic operators are used to perform mathematical calculations.
LIST OF ARITHMETIC OPERATORS
Addition
Symbol: plus
Example: 5 plus 3
Result: 8
Subtraction
Symbol: minus
Example: 5 minus 3
Result: 2
Multiplication
Symbol: star
Example: 5 multiplied by 3
Result: 15
Division
Symbol: slash
Example: 5 divided by 2
Result: 2.5
Modulus
Symbol: percent
Example: 5 modulus 2
Result: 1
Floor Division
Symbol: double slash
Example: 5 floor divided by 2
Result: 2
Exponentiation
Symbol: double star
Example: 2 power 3
Result: 8
ARITHMETIC OPERATOR EXAMPLES IN PYTHON
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a % b)
print(a // b)
print(a ** b)
IMPORTANT NOTES FOR EXAMS
Division always produces a decimal result
Floor division removes the decimal part
Modulus gives remainder
Exponentiation is used for power calculations
3.8.2 BITWISE OPERATORS
Bitwise operators work on the binary form of numbers. These operators perform operations directly on bits, which makes them important for low-level programming.
Example
Decimal 5 in binary is 101
Decimal 3 in binary is 011
LIST OF BITWISE OPERATORS
Bitwise AND
Symbol: ampersand
Works when both bits are one
Bitwise OR
Symbol: vertical bar
Works when at least one bit is one
Bitwise XOR
Symbol: caret
Works when bits are different
Bitwise NOT
Symbol: tilde
Inverts all bits
Left Shift
Symbol: double left shift
Moves bits to the left
Right Shift
Symbol: double right shift
Moves bits to the right
BITWISE AND EXAMPLE
5 AND 3
Binary calculation
101
011
Result: 001 which is 1
BITWISE OR EXAMPLE
5 OR 3
Binary calculation
101
011
Result: 111 which is 7
BITWISE XOR EXAMPLE
5 XOR 3
Binary calculation
101
011
Result: 110 which is 6
BITWISE NOT EXAMPLE
NOT 5
Result is minus 6
Explanation
Bitwise NOT uses two’s complement logic
Formula: NOT x equals negative of x plus one
LEFT SHIFT OPERATOR
Example
5 left shift 1
Binary
101 becomes 1010
Result is 10
Each left shift multiplies the number by 2
RIGHT SHIFT OPERATOR
Example
5 right shift 1
Binary
101 becomes 10
Result is 2
Each right shift divides the number by 2
IMPORTANT FBISE NOTES
Bitwise operators work only with integers
Left shift fills zeros on the right
Right shift removes rightmost bits
Used in system-level and optimization tasks
3.8.3 MEMBERSHIP OPERATORS
Membership operators are used to check whether a value exists in a sequence such as a string or a list.
MEMBERSHIP OPERATORS
in
Returns true if value exists
not in
Returns true if value does not exist
EXAMPLE WITH STRING
text = "Pakistan"
print("P" in text)
print("x" in text)
EXAMPLE WITH LIST
numbers = [1, 2, 3, 4]
print(3 in numbers)
print(10 not in numbers)
USAGE IN CONDITIONS
if "a" in "apple":
print("Found")
Membership operators are commonly used in decision-making logic.
3.8.4 COMPARISON OPERATORS
Comparison operators are used to compare two values. The result of a comparison is always true or false.
LIST OF COMPARISON OPERATORS (WRITTEN FORM)
Equal to
Not equal to
Greater than
Less than
Greater than or equal to
Less than or equal to
COMPARISON EXAMPLES IN PYTHON
a = 10
b = 20
print(a equals b)
print(a not equals b)
print(a greater than b)
print(a less than b)
print(a greater than or equal to b)
print(a less than or equal to b)
STRING COMPARISON EXAMPLE
print("apple" equals "apple")
print("Apple" equals "apple")
Python comparisons are case-sensitive.
USE IN DECISION MAKING
marks = 75
if marks greater than or equal to 50:
print("Pass")
else:
print("Fail")
IMPORTANT EXAM POINTS
Comparison operators return Boolean values
Used with if and while statements
Assignment is different from comparison
Confusing assignment with comparison is a common mistake
CONCLUSION
Operators are the foundation of programming logic. Arithmetic operators perform calculations, bitwise operators work on binary data, membership operators test presence in sequences, and comparison operators help in decision making. A strong understanding of operators is essential for solving problems and writing efficient Python programs.
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: