Hackforge Academy

Category: python

Python Operators

Published on 24 Jul 2026

Explanation

Arithmetic operators are used to perform mathematical calculations on numeric values. Python supports addition (+), subtraction (-), multiplication (*), division

Code:

a = 20
b = 6

print('Addition:', a + b)
print('Subtraction:', a - b)
print('Multiplication:', a * b)
print('Division:', a / b)
print('Floor Division:', a // b)
print('Modulus:', a % b)
print('Power:', a ** 2)

Explanation

Comparison operators compare two values and return either True or False. These operators are commonly used in decision-making statements such

Code:

x = 15
y = 20

print('Equal:', x == y)
print('Not Equal:', x != y)
print('Greater Than:', x > y)
print('Less Than:', x < y)
print('Greater or Equal:', x >= y)
print('Less or Equal:', x <= y)

Explanation

Logical operators combine multiple conditions and return a Boolean value. Python provides 'and', 'or', and 'not'. The 'and' operator returns

Code:

age = 25
salary = 50000

print(age > 18 and salary > 30000)
print(age < 18 or salary > 30000)
print(not(age > 30))

count = 10
count += 5
print(count)

count *= 2
print(count)

count -= 8
print(count)

Explanation

Membership operators determine whether a value exists inside a sequence such as a string, list, tuple, or set. The 'in'

Code:

languages = ['Python', 'Java', 'C++']

print('Python' in languages)
print('Go' not in languages)

list1 = [10, 20, 30]
list2 = list1
list3 = [10, 20, 30]

print(list1 is list2)
print(list1 is list3)
print(list1 == list3)

Explanation

Type casting is the process of converting one data type into another. Python provides built-in functions such as int(), float(),

Code:

number = '100'
price = '99.95'

num = int(number)
amount = float(price)

print(num + 50)
print(amount + 10)

age = 30
print('Age: ' + str(age))

print(bool(1))
print(bool(0))

marks = input('Enter your marks: ')
marks = int(marks)
print('Total Marks:', marks)

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community