0% found this document useful (0 votes)
14 views4 pages

Second Week Note

The document explains various types of operators in Python, including Arithmetic, Comparison, Logical, and Assignment Operators. Each category is described with examples demonstrating their functionality. These operators are essential for performing operations and controlling logic flow in Python.

Uploaded by

dagiyoni924
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)
14 views4 pages

Second Week Note

The document explains various types of operators in Python, including Arithmetic, Comparison, Logical, and Assignment Operators. Each category is described with examples demonstrating their functionality. These operators are essential for performing operations and controlling logic flow in Python.

Uploaded by

dagiyoni924
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/ 4

4.

Operators in python
In Python, operators are symbols used to perform
operations on variables and values. They are
categorized into different types based on their
functionality.
4.1. Arithmetic Operators
These operators perform basic mathematical
operations.
Example:
a = 10
b=3
print(a + b) # Addition: 10 + 3 = 13
print(a - b) # Subtraction: 10 - 3 = 7
print(a * b) # Multiplication: 10 * 3 = 30
print(a / b) # Division: 10 / 3 = 3.3333...
print(a // b) # Floor Division: 10 // 3 = 3
print(a % b) # Modulus: 10 % 3 = 1 (remainder)
print(a ** b) # Exponentiation: 10 ** 3 = 1000
4.2. Comparison Operators
These operators are used to compare two values
and return a Boolean result (True or False).
Example:
x=5
y=3
print(x == y) # Equal to: False
print(x != y) # Not equal to: True
print(x > y) # Greater than: True
print(x < y) # Less than: False
print(x >= y) # Greater than or equal: True
print(x <= y) # Less than or equal: False
4.3. Logical Operators
These operators are used to combine conditional
statements and return a Boolean result.
Example:
a=5
b=3
c=8
print(a > b and c > a) # True: both conditions are
True
print(a < b or c > a) # True: at least one condition
is True
print(not(a == b)) # True: because a is not equal to
b
4.4. Assignment Operators
These operators are used to assign values to
variables. They also combine operations with
assignment.
Example:
x=5
x += 3 # x = x + 3, so x becomes x
x -= 2 # x = x - 2, so x becomes 6
x *= 2 # x = x * 2, so x becomes 12
x /= 3 # x = x / 3, so x becomes 4.0 print(x) #
Output: 4.0
Summary:
Arithmetic Operators are used for basic math
operations.
Comparison Operators are used to compare
values and return True or False.
Logical Operators are used to combine
conditions.
Assignment Operators are used to assign and
modify the values of variables.
These operators are essential for performing
operations and controlling the flow of logic in
Python!

You might also like