|4. Operators in Python
Chapter 4Python Tutorial~1 min read

Operators in Python

Operators — calculations आणि comparisons

Operator म्हणजे values वर operations करायचे symbols. Python मध्ये arithmetic, comparison, logical, assignment असे operators आहेत. हे सगळ्या programs मध्ये रोज वापरले जातात.

Arithmetic Operators — गणित

Basic arithmetic

python
a = 10
b = 3

print(a + b)   # 13  — बेरीज
print(a - b)   # 7   — वजाबाकी
print(a * b)   # 30  — गुणाकार
print(a / b)   # 3.333... — भागाकार (float)
print(a // b)  # 3   — floor division (पूर्ण भाग)
print(a % b)   # 1   — modulus (उरलेला भाग)
print(a ** b)  # 1000 — a ची b power (10³)

Comparison Operators — तुलना

Comparison — result True/False असतो

python
x = 10
y = 20

print(x == y)   # False — बरोबर आहे का?
print(x != y)   # True  — वेगळे आहेत का?
print(x < y)    # True  — लहान आहे का?
print(x > y)    # False — मोठे आहे का?
print(x <= 10)  # True  — लहान किंवा बरोबर?
print(x >= 10)  # True  — मोठे किंवा बरोबर?

Logical Operators — आणि/किंवा/नाही

and, or, not

python
age = 20
has_id = True

# and — दोन्ही True असेल तरच True
print(age >= 18 and has_id)   # True

# or — कोणतेही एक True असेल तर True
print(age < 18 or has_id)     # True

# not — उलट करतो
print(not has_id)              # False

Assignment Operators

Shorthand assignment

python
count = 10

count += 5   # count = count + 5 → 15
count -= 3   # count = count - 3 → 12
count *= 2   # count = count * 2 → 24
count //= 5  # count = count // 5 → 4
count **= 3  # count = count ** 3 → 64
print(count) # 64

Key Points — लक्षात ठेवा

  • // = floor division (integer result), % = modulus (remainder)
  • ** = power/exponent (2**3 = 8)
  • == comparison, = assignment — गोंधळू नका!
  • and, or, not — logical operators
  • += shorthand: x += 5 म्हणजे x = x + 5
0/12 chapters पूर्ण