Practical Python Operators Types
Practical Python Operators Types
Practical Python Operators Types
Objective:
To understand and apply different types of operators in Python such as arithmetic, relational, logical,
To work with different data types such as integers, floats, and strings.
Theory/Concept:
- Operators: Operators are special symbols used to perform operations on values or variables.
Algorithm:
1. Choose two variables with different types (e.g., integer and float).
Code:
```python
# Arithmetic Operators
a = 10
b=3
print('Arithmetic Operators:')
print(f'Addition: {a + b}')
print(f'Subtraction: {a - b}')
print(f'Multiplication: {a * b}')
print(f'Division: {a / b}')
print(f'Modulus: {a % b}')
print(f'Exponentiation: {a ** b}')
# Relational Operators
print('\nRelational Operators:')
print(f'a == b: {a == b}')
print(f'a != b: {a != b}')
x = True
y = False
print('\nLogical Operators:')
print(f'x or y: {x or y}')
# Assignment Operators
a += 5
print('\nAssignment Operators:')
```
Output:
Arithmetic Operators:
Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3.3333333333333335
Integer Division: 3
Modulus: 1
Exponentiation: 1000
Relational Operators:
a == b: False
a != b: True
a > b: True
a < b: False
a >= b: True
a <= b: False
Logical Operators:
x and y: False
x or y: True
not x: False
Assignment Operators:
a after a += 5: 15
Conclusion:
This program demonstrated the use of various operators in Python, such as arithmetic, relational,
I learned how to work with different data types (integers, floats, and booleans) and perform
operations on them.