__author__ = "Narendra Boyina"
# -----------------------------------------------------------------------------
# Copyright (c) 2025 BR Technologies PVT LTD
# -----------------------------------------------------------------------------
"""
Topics to be covered in today's class:
--> classification of operators
--> Arithmetic operators
--> Comparison operators
--> Logical operators
--> Assignment operators
--> Identity operators
"""
"""
operators are classified in to 3 types
1. Unary operators (python don't support Unary operators) Ex: a++ a-- ++a --a
2. binary operators --> Which requires 2 Operends to perform operation Ex: a+b x-y
3. ternary operators --> Which requires 3 Operends to perform operation a b c
"""
""" Binary operators ()"""
"""
1. Arithmetic operators
Arithmetic operators are used to perform mathematical operations like addition,
subtraction, multiplication, division, modulus, floor division, power ..etc.
"""
# print("******** Arithmetic operators ********")
x = 9 # this is 1st input --> initialization
y = 2 # this is 2nd input --> initialization
# print('addition value = ', x+y) # this will perform addition
# Subtract right operand from the left
# print('Subtract value = ', x - y)
# Multiply two operands
# print('x * y =', x * y)
# Divide left operand by the right one (always results into float)
# print('x / y =', x / y) # Always output of division operator is Float data type
# Modulus - remainder of the division of left operand by the right (x % y (remainder of x/y) )
# print('x % y =', x % y)
# # # Floor division with integer - division that results into whole number adjusted to the left in the number line
"""
If both inputs are integer values then output will be integer,
if any one of input value is float data type then result will be float value
"""
x = 5
y = 3
# print("x / y =", x / y)
# print('x // y =', x//y)
# # Floor division - with float values
x = 50
y = 4.5
# print('x // y =',x//y)
# # ** acts as power
x = 2
y = 3
# print('x ** y =', x**y)
# salary expense tracker monthly
# salary = 100000
# rent = 10000
# utilities = 2000
# personal = 10000
# expenses = rent + utilities + personal
# saving = salary - expenses
# print("monthly salary :", salary)
# print("monthly expenses are :", expenses)
# print("monthly savings are :", saving)
# emi = 45762
# saving = saving - 45762
# print(saving)
"""
2. Comparison operators
=======================
Comparison operators are used to compare values.
It either returns True or False according to the condition.
"""
# print("******** Comparison operators ********")
x = 10
y = 12
# print('x > y is', x > y)
# #
# print('x < y is', x < y)
# #
# print('x >= y is', x >= y)
# #
# print('x <= y is', x <=y)
# #
# print('x == y is', x == y)
# #
# print('x != y is', x != y)
"""
3. Logical operators
===================
Logical operators are the and, or, not operators
It either returns True or False according to the condition"""
# print("******** Logical operators ********")
# x = True
# y = False
#
# print('x and y is', x and y)
# print('x or y is', x or y)
# print(not y)
"""
4. Assignment operators
======================
Assignment operators are the extention of arthametic operators
Assignment operators are used in Python to assign values to variables.
a = 5 is a simple assignment operator that assigns the value 5 on the right to the variable a on the left.
There are various compound operators in Python like a += 5 that adds to the variable and later assigns the same.
It is equivalent to a = a + 5.
Operator Example Equivalent to
+= =====> x += 5 ===> x = x + 5
-= =====> x -= 5 ===> x = x - 5
*= =====> x *= 5 ===> x = x * 5
/= =====> x /= 5 ===> x = x / 5
%= =====> x %= 5 ===> x = x % 5
**= =====> x **= 5 ===> x = x ** 5
"""
# print("******** Assignment operators ********")
# x = 5
# x += 5 # x = x + 5 it is a in-line comment
# print(x)
# x -= 5 # x= x-5
# print(x)
#
# x *= 5
# print(x)
# #
# x /= 5 # x =x/5
# print(x)
#
# x = 42 # TAKEN NEW X VALUE
# x %= 5 # x = x % 5 Modulus operator will give remainder value
# print(x)
#
#
# x = 18 # TAKEN NEW X VALUE
# x //= 5 # x = x // 5
# print(x)
#
# x = 2
# x **= 4 # x = x**4
# print(x)
"""
5. Identity operators
=================
"is" and "is not" are the identity operators in Python.
They are used to check if two values (or variables) are located on the same part of the memory.
"""
# print("******** Identity operators ********")
# x1 = 15 # initialisation
# print(type(x1))
# print(id(x1)) # to check memory address we have to use id() builtin-function
# y1 = 15
# print(id(y1))
# print(x1 is y1)
# print(x1 is not y1)
# x2 = 'Narendra'
# print(type(x2))
# print(id(x2))
# y2 = 'Narendra'
# print(id(y2))
# print(x2 is y2) # Output:
# x3 = [1, 2, 3] # if you place multiple values inside Square brackets separated by coma operator
# print(type(x3))
# print(id(x3))
# y3 = [1, 2, 3]
# print(id(y3))
# print(x3 is y3)
# x3 = (1, 2, 3) # tuple => Immutable object
# print(type(x3))
# print(id(x3))
# y3 = (1, 2, 3)
# print(id(y3))
# print(x3 is y3)Author: Boyina Narendra
Supporting Author: M. Meera Sindhu
Request: If you find this information useful, please provide your valuable comments
No comments:
Post a Comment