What Python Operators in Hindi– Python में ऑपरेटर क्या होता है?

  • Python मे operator एक symbol है जिसका उपयोग values पर कुछ कार्य करने के लिए किया जाता है। 
  • यह  program को नंबर जोड़ने, मानो की तुलना करने या डेटा को स्टोर करने जैसे कार्यों को करने में मदद करता है। 
  • Operators का उपयोग values या variables के साथ किया जाता है ताकि ताकि प्रोग्राम सही ढंग से कार्य कर सके।  
  • Python, के पास विभिन्न कार्यों को करने के लिए अलग-अलग ऑपरेटर होते है। 
  • Operators बहुत जरूरी होते हैं क्योंकि ये प्रोग्राम को निर्णय लेने और सही तरीके से स्टेप्स चलाने में मदद करते हैं। 
  • Operators, का उपयोग करके हम python में सरल तरीके से शक्तिशाली और उपयोगी प्रोग्राम का निर्माण कर सकते हैं।  

 

Types of Operators in Python – Python में ऑपरेटर के प्रकार

Python में ऑपरेटर के निम्न प्रकार होते हैं।
 
 1) Arithmetic Operators – गणितीय ऑपरेटर
 2) Assignment Operators – असाइनमेंट ऑपरेटर
 3) Comparison Operators – तुलना करने वाले ऑपरेटर
 4) Logical Operators – लॉजिकल ऑपरेटर
 5) Bitwise Operators – बिटवाइज़ ऑपरेटर
6) Membership Operators – मेंबरशिप ऑपरेटर
 7) Identity Operators – आइडेंटिटी ऑपरेटर

python operators
 

Arithmetic Operators – गणितीय ऑपरेटर

Arithmetic operators, का उपयोग math operations के लिए किया जाता है। इसमें addition, subtraction, multiplication, division, modulus, और exponentiation शामिल है। 

ये  नंबर्स का उपयोग करके मानो की गणना करने में मदद करते हैं। 
उदाहरण के लिए आप दो नंबरों को जोड़ सकते हैं या जब एक नंबर को दूसरे नंबर से भाग दिया जाता है तब आप remainder(शेषफल ) का पता लगा सकते हैं। 


Arithmetic Operators Table 

Operator Symbol Example
Addition + 10 + 15 = 25
Subtraction - 10 - 12 = 2
Multiplication * 10 * 3 = 30
Division / 10 / 2 = 5.0
Modulus % 10 % 3 = 1
Floor Division // 10 // 3 = 3
Exponentiation ** 2 ** 3 = 8


 

Program for Arithmetic Operators 

a = 5
b = 7
print("Addition:", a + b)     # 5 + 7 = 12
print("Subtraction:", a - b)     # 5 - 7 = -2
print("Multiplication:", a * b)  # 5 * 7 = 35
print("Division:", a / b)            # 5 / 7 = 0.714...
print("Floor Division:", a // b) # 5 // 7 = 0
print("Modulus:", a % b)         # 5 % 7 = 5
print("Power:", a ** b)     # 5 ** 7 = 78125
Output:
Addition: 12
Subtraction: -2
Multiplication: 35
Division: 0.7142857142857143
Floor Division: 0
Modulus: 5
Power: 78125


Assignment Operators – असाइनमेंट ऑपरेटर

Assignment operators, का उपयोग एक variable में value स्टोर करने के लिए किया जाता है। 

यह ऑपरेटर केवल वैरिएबल में वैल्यू स्टोर करने तक सीमित नहीं हैं परंतु यह किसी वैल्यू को जोड़ने, घटाने, गुणा या भाग करने जैसे काम भी करते हैं और वैरिएबल की वैल्यू को सीधे अपडेट भी कर सकते हैं।


Assignment Operators Table  

Operator Symbol Example
Assignment = x = 10
Add and Assign += x += 5
(x = x + 5)
Subtract and Assign -= x -= 3
(x = x - 3)
Multiply and Assign *= x *= 2
(x = x * 2)
Divide and Assign /= x /= 2
(x = x / 2)
Modulus and Assign %= x %= 3
(x = x % 3)
Floor Division and Assign //= x //= 2
(x = x // 2)
Exponent and Assign **= x **= 3
(x = x ** 3)
Bitwise AND and Assign &= x &= 2
(x = x & 2)
Bitwise OR and Assign |= x |= 3
(x = x | 3)
Bitwise XOR and Assign ^= x ^= 1
(x = x ^ 1)
Bitwise Left Shift and Assign <<= x <<= 1
(x = x << 1)
Bitwise Right Shift and Assign >>= x >>= 1
(x = x >> 1)



Program for Assignment Operators

x = 10         # Set x to 10
print(x)
x += 5         # x = x + 5 → 15
print(x)
x -= 3         # x = x - 3 → 12
print(x)
x *= 2         # x = x * 2 → 24
print(x)
x /= 4         # x = x / 4 → 6.0
print(x)
x %= 4         # x = x % 4 → 2.0
print(x)
x **= 2        # x = x ** 2 → 4.0
print(x)
x //= 2        # x = x // 2 → 2.0
print(x)
Output:
10
15
12
24
6.0
2.0
4.0
2.0
 

Comparison Operators – तुलना करने वाले ऑपरेटर

Comparison operators, का उपयोग values की तुलना करने के लिए करते हैं। ये जांचते हैं कि क्या मान बराबर हैं, बराबर नहीं हैं, अधिक हैं, कम हैं, अधिक या बराबर हैं, या कम या बराबर हैं। 

परिणाम हमेशा या तो true या false होता है और इसका उपयोग मुख्यतः conditions में होता है।


Comparison Operators Table 

Operator Symbol Example
Equal to == 7 == 7→ True
Not equal to != 5 != 4 → True
Greater than > 7 > 4 → True
Less than < 5 < 8 → True
Greater than or equal to >= 6 >= 6 → True
Less than or equal to <= 3 <= 5 → True
 


Program for Comparison Operators

a = 7
b = 5
print('a == b:', a == b)   # Equal to
print('a != b:', a != b)   # Not equal to
print('a > b:', a > b)     # Greater than
print('a < b:', a < b)     # Less than
print('a >= b:', a >= b)   # Greater than or equal to
print('a <= b:', a <= b)   # Less than or equal to
Output:
a == b: False
a != b: True
a > b: True
a < b: False
a >= b: True
a <= b: False
 
इसे भी पढ़ें 👇


Logical Operators – लॉजिकल ऑपरेटर

Logical operators, का उपयोग दो या अधिक conditions को जोड़ने के लिए किया जाता है। 
 
Logical operators, निर्णय लेने वाले भागों जैसे if statements और loops, में बहुत उपयोगी है जहां  हमें एक समय में एक से अधिक नियमों को जांच करने की जरूरत होती है। 

AND, OR, और NOT तीन मुख्य logical operators  हैं।


Logical Operators Table

Operator Symbol Example
Logical AND and (5 > 2) and (4 < 6) → True
Logical OR or (5 < 2) or (4 < 6) → True
Logical NOT not not (5 > 2) → False
 

Program for Logical Operators

x = 8
y = 12
print("AND Operator:", x < 10 and y < 15)   
print("OR Operator:", x > 10 or y < 10)     
print("NOT Operator:", not(x > y))
Output:
AND Operator: True
OR Operator: False
NOT Operator: True
 

Bitwise Operators – बिटवाइज़ ऑपरेटर

Bitwise operators, नंबर्स के बाइनरी फॉर्म के साथ कार्य करता है। ये bits को सीधे बदलते या तुलना करते हैं। 

AND, OR, XOR, NOT, left shift, और right shift, सामान्य bitwise operators है। ये मुख्यत: प्रोग्रामिंग कार्य में उपयोग किए जाते हैं जहां bits या memory के साथ सीधे ही प्रोसेसिंग या कार्य करने की जरूरत होती है। 


Bitwise Operators Table

Operator Symbol Example
Bitwise AND & 5 & 3 → 1
(0101 & 0011 = 0001)
Bitwise OR | 5 | 3 → 7
(0101 | 0011 = 0111)
Bitwise XOR ^ 5 ^ 3 → 6
(0101 ^ 0011 = 0110)
Bitwise NOT ~ ~5 → -6
(Inverts all bits)
Left Shift << 5 << 1 → 10
(0101 becomes 1010)
Right Shift >> 5 >> 1 → 2
(0101 becomes 0010)
 


Program for Bitwise Operators

x = 5   # Binary: 0101
y = 3   # Binary: 0011
print("x & y =", x & y)    # Bitwise AND
print("x | y =", x | y)    # Bitwise OR
print("x ^ y =", x ^ y)    # Bitwise XOR
print("~x =", ~x)          # Bitwise NOT (for x)
print("x << 1 =", x << 1)  # Left shift
print("x >> 1 =", x >> 1)  # Right shift
Output:
x & y = 1
x | y = 7
x ^ y = 6
~x = -6
x << 1 = 10
x >> 1 = 2
 

Membership Operators

Membership operators, का उपयोग यह जांच करने के लिए किया जाता है कि क्या कोई value एक sequence जैसे  ( list, string, या tuple) में उपस्थित है या नहीं।  
`in` और `not in` , दो membership operators

 in:  

यह True लौटता है यदि वैल्यू sequence में मौजूद है। 

 not in: 

यह  True लौटता है यदि वैल्यू मौजूद  नहीं है।  

ये operators, data structures जैसे lists या strings में elements को ढूंढने के लिए उपयोगी है।

Program for Membership Operators 

x = "Language"
print("L" in x)    # Output:True
print("p" in x)    # Output:False
# Example 2: Using 'not in' and 'in' with a list
nums = [15, 25, 30]
print(40 not in nums) # Output:True
print(25 not in nums) # Output:False
print(10 in nums)     # Output:False 
# Example 4: Using 'not in' with a string
name = "Python"
print("s" not in name) # Output:True
print("P" not in name) # Output:False


Identity Operators in Hindi - आइडेंटिटी ऑपरेटर्स 

Identity operators, का उपयोग दो objects के memory location की तुलना करने के लिए किया जाता है।  
 `is` और `is not` दो identity operators है।

is:

True लौटता है यदि दोनो variables, एक ही object को refer करते है।

is not:

True लौटता है यदि दोनो variables, एक ही object को refer नही करते है। 

ये operators यह जांच करने में मदद करते हैं कि क्या दो वेरिएबल एक ही मेमोरी एड्रेस को point करते हैं।


Program for Identity Operators

# Example 1: Using 'is' with lists
a = [1, 2, 3]
b = a
print(a is b)  # Output: True

# Example 2: Using 'is not' with lists
x = [10, 20, 30]
y = [10, 20, 30]
print(x is not y)  # Output: True

# Example 3: Using 'is' with small integers
num1 = 200
num2 = 200
print(num1 is num2)  # Output: True

# Example 4: Using 'is' with strings
s1 = "good"
s2 = "good"
print(s1 is s2)  # Output: True

Explanation
1) Example 1, में a और b एक ही list, को point करता है अतः a और b, True है।

2) Example 2, में x और y में समान values है परंतु अलग अलग lists, है अतः x is not y, True है।


Operator Precedence and Associativity in Hindi 


Operator Precedence

Python, में operator precedence यह बताता है कि कौन से ऑपरेशन को पहले किया जाना है।  कुछ ऑपरेटर्स higher precedence वाले होते हैं अतः उन्हें पहले Run किया जाता है। 

उदाहरण के लिए , multiplication, addition से ज्यादा higher precedence वाले होते हैं अतः multiplication को addition कि पहले Run किया जाता है।

Program for Operator Precedence

x = 10 + 5 * 2
y = (10 + 5) * 2
print(x, y)
Output:
20 30
  
Explanation:
1) `x = 10 + 5 * 2` → multiplication पहले होता है। 
 `10 + 10 = 20`

2)  `y = (10 + 5) * 2`
इसमें parentheses पहले रन होता । 
15 * 2 = 30`


Associativity

Associativity यह बताता है कि जब दो ऑपरेटर की ताकत (precedence) बराबर होती है, तो उन्हें किस दिशा में हल किया जाएगा बाएँ से दाएँ या दाएँ से बाएँ।

अधिकांश ऑपरेटर बाएँ से दाएँ काम करते हैं, लेकिन पावर (`**`) ऑपरेटर दाएँ से बाएँ काम करता है।

Program for Associativity

x = 100 / 10 * 2 + 5 - 3
print(x)
Output:
22.0
 

Explanation:
Operator Precedence Order:
 1)  `/` और `*`,  `+` और `-`की अपेक्षा higher precedence होते है। 

2)  `/` और `*`, दोनो समान precedence वाले होते है और ये ऑपरेटर्स left-to-right associative होते हैं।

3) वैसे ही  `+` और `-` के लिए होता है।

4) अतः Python निम्न प्रकार से गणना करता है।
    100 / 10 = 10.0
    10.0 * 2 = 20.0
   20.0 + 5 = 25.0
   25.0 - 3 = 22.0

4)  Final Result:
22.0