मुख्य कंटेंट पर जाएं
Python Operators in Hindi
PYTHON PROGRAMMING 12 मिनट पढ़ें 3 बार पढ़ा गया

Python Operators in Hindi

Lavkush Chakrawarti

परिचय

Operator क्या है?

Operand क्या है?

Python Operators के प्रकार

1. Arithmetic Operators (अंकगणितीय ऑपरेटर्स)

Addition (+)

Subtraction (-)

Multiplication (*)

Division (/)

Floor Division (//)

Modulus (%)

Exponent (**)

Arithmetic Operators का संयुक्त उदाहरण

2. Assignment Operators (असाइनमेंट ऑपरेटर्स)

उदाहरण

3. Comparison (Relational) Operators

उदाहरण

4. Logical Operators

AND Operator

OR Operator

NOT Operator

5. Bitwise Operators

उदाहरण

6. Identity Operators

उदाहरण

7. Membership Operators

उदाहरण

Operator Precedence (ऑपरेटर प्राथमिकता)

सामान्य Precedence

उदाहरण

Parentheses का उपयोग

सभी Operators का सारांश

Best Practices

परीक्षा की दृष्टि से महत्वपूर्ण तथ्य

Frequently Asked Questions (FAQs)

प्रश्न 1. Operator क्या होता है?

प्रश्न 2. Python में कितने प्रकार के Operators होते हैं?

प्रश्न 3. == और = में क्या अंतर है?

प्रश्न 4. // और / में क्या अंतर है?

प्रश्न 5. in Operator का उपयोग कहाँ होता है?

Quick Revision

अगला अध्याय

 

परिचय

Programming में केवल डेटा (Data) को Store करना ही पर्याप्त नहीं होता, बल्कि उस डेटा पर विभिन्न प्रकार की गणनाएँ (Calculations), तुलना (Comparison) और निर्णय (Decision Making) भी करने पड़ते हैं। इन सभी कार्यों को करने के लिए Operators का उपयोग किया जाता है।

Operator एक विशेष चिन्ह (Symbol) या Keyword होता है जो एक या अधिक Operands (मान/Variables) पर कोई विशेष कार्य (Operation) करता है और परिणाम (Result) देता है।

उदाहरण के लिए, यदि हमें दो संख्याओं का जोड़ करना हो, दो मानों की तुलना करनी हो या यह जाँचना हो कि कोई शर्त सही (True) है या नहीं, तो Operators का उपयोग किया जाता है।

Python में कई प्रकार के Operators उपलब्ध हैं, जिनका उपयोग अलग-अलग परिस्थितियों में किया जाता है।

 

Operator क्या है?

Operator वह चिन्ह (Symbol) या Keyword है जो किसी Variable या Value पर कोई विशेष कार्य करता है।

उदाहरण—

a = 10

b = 20

 

print(a + b)

Output

30

यहाँ + एक Arithmetic Operator है।

 

Operand क्या है?

जिस Value या Variable पर Operator कार्य करता है, उसे Operand कहते हैं।

उदाहरण—

x = 15

y = 5

 

print(x * y)

यहाँ—

  • x पहला Operand है।
  • y दूसरा Operand है।
  • * Operator है।

 

Python Operators के प्रकार

Python में मुख्य रूप से निम्न प्रकार के Operators होते हैं—

  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison (Relational) Operators
  4. Logical Operators
  5. Bitwise Operators
  6. Identity Operators
  7. Membership Operators

 

  1. Arithmetic Operators (अंकगणितीय ऑपरेटर्स)

Arithmetic Operators का उपयोग गणितीय (Mathematical) गणनाओं के लिए किया जाता है।

Operator

कार्य

उदाहरण

+

जोड़ (Addition)

a + b

-

घटाना (Subtraction)

a - b

*

गुणा (Multiplication)

a * b

/

भाग (Division)

a / b

//

पूर्णांक भाग (Floor Division)

a // b

%

शेषफल (Modulus)

a % b

**

घात (Exponent)

a ** b

 

Addition (+)

a = 15

b = 5

 

print(a + b)

Output

20

 

Subtraction (-)

print(20 - 8)

Output

12

 

Multiplication (*)

print(12 * 5)

Output

60

 

Division (/)

print(20 / 4)

Output

5.0

/ हमेशा Float परिणाम देता है।

 

Floor Division (//)

print(17 // 5)

Output

3

यह केवल पूर्णांक (Integer) भाग देता है।

 

Modulus (%)

print(17 % 5)

Output

2

यह भाग देने के बाद बचा हुआ शेषफल (Remainder) देता है।

 

Exponent (**)

print(2 ** 4)

Output

16

 

Arithmetic Operators का संयुक्त उदाहरण

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("Exponent :", a ** 2)

 

  1. Assignment Operators (असाइनमेंट ऑपरेटर्स)

Assignment Operators का उपयोग Variables में Value Assign या Update करने के लिए किया जाता है।

Operator

उदाहरण

अर्थ

=

x = 10

Value Assign

+=

x += 5

x = x + 5

-=

x -= 5

x = x - 5

*=

x *= 5

x = x * 5

/=

x /= 5

x = x / 5

//=

x //= 5

Floor Division Assign

%=

x %= 5

Modulus Assign

**=

x **= 2

Exponent Assign

 

उदाहरण

x = 10

 

x += 5

print(x)

Output

15

 

  1. Comparison (Relational) Operators

इनका उपयोग दो Values की तुलना (Comparison) करने के लिए किया जाता है।

Operator

अर्थ

==

बराबर

!=

बराबर नहीं

बड़ा

छोटा

>=

बड़ा या बराबर

<=

छोटा या बराबर

 

उदाहरण

a = 15

b = 20

 

print(a == b)

print(a != b)

print(a > b)

print(a < b)

Output

False

True

False

True

 

  1. Logical Operators

Logical Operators का उपयोग एक से अधिक Conditions को जोड़ने के लिए किया जाता है।

Operator

अर्थ

and

दोनों True हों

or

कोई एक True हो

not

Result उल्टा कर देता है

 

AND Operator

age = 20

citizen = True

 

print(age >= 18 and citizen)

Output

True

 

OR Operator

print(True or False)

Output

True

 

NOT Operator

print(not True)

Output

False

 

  1. Bitwise Operators

Bitwise Operators Binary Bits पर कार्य करते हैं।

Operator

कार्य

&

AND

|

OR

^

XOR

~

NOT

<< 

Left Shift

>> 

Right Shift

उदाहरण

print(5 & 3)

Output

1

Bitwise Operators का उपयोग Low-Level Programming, Networking, Embedded Systems और Performance आधारित Applications में अधिक किया जाता है।

 

  1. Identity Operators

Identity Operators यह जाँचते हैं कि दो Variables एक ही Object को Refer कर रहे हैं या नहीं।

Operator

अर्थ

is

समान Object

is not

समान Object नहीं

 

उदाहरण

a = [1, 2]

b = a

 

print(a is b)

Output

True

 

  1. Membership Operators

Membership Operators का उपयोग यह जाँचने के लिए किया जाता है कि कोई Value किसी Sequence (List, Tuple, String, Set, Dictionary आदि) में मौजूद है या नहीं।

Operator

अर्थ

in

मौजूद है

not in

मौजूद नहीं है

 

उदाहरण

fruits = ["Apple", "Mango", "Banana"]

 

print("Mango" in fruits)

print("Orange" not in fruits)

Output

True

True

 

Operator Precedence (ऑपरेटर प्राथमिकता)

जब एक Expression में कई Operators होते हैं, तो Python एक निश्चित क्रम (Order of Precedence) के अनुसार उन्हें Execute करता है।

सामान्य Precedence

  1. () Parentheses
  2. ** Exponent
  3. *, /, //, %
  4. +, -
  5. Comparison Operators
  6. not
  7. and
  8. or

 

उदाहरण

print(5 + 2 * 3)

Output

11

पहले 2 * 3 = 6 होगा, फिर 5 + 6 = 11।

 

Parentheses का उपयोग

print((5 + 2) * 3)

Output

21

 

सभी Operators का सारांश

Operator Type

उपयोग

Arithmetic

गणितीय कार्य

Assignment

Value Assign करना

Comparison

तुलना करना

Logical

Conditions जोड़ना

Bitwise

Binary Bits पर कार्य

Identity

Object की पहचान

Membership

Collection में Value ढूँढना

 

Best Practices

  • जटिल Expressions में Parentheses () का उपयोग करें।
  • == और = में अंतर समझें।
  • Bitwise Operators का उपयोग तभी करें जब उनकी आवश्यकता हो।
  • Membership और Identity Operators का उपयोग सही परिस्थिति में करें।
  • Code को पढ़ने योग्य (Readable) बनाए रखें।

 

परीक्षा की दृष्टि से महत्वपूर्ण तथ्य

  • +, -, *, / Arithmetic Operators हैं।
  • = Assignment Operator है।
  • == Comparison Operator है।
  • and, or, not Logical Operators हैं।
  • is और is not Identity Operators हैं।
  • in और not in Membership Operators हैं।
  • // Floor Division तथा % Modulus Operator है।
  • () की Priority सबसे अधिक होती है।

 

Frequently Asked Questions (FAQs)

प्रश्न 1. Operator क्या होता है?

Operator एक Symbol या Keyword है जो Variables या Values पर कोई Operation करता है।

प्रश्न 2. Python में कितने प्रकार के Operators होते हैं?

मुख्य रूप से 7 प्रकार—Arithmetic, Assignment, Comparison, Logical, Bitwise, Identity और Membership।

प्रश्न 3. == और = में क्या अंतर है?

= का उपयोग Value Assign करने के लिए होता है, जबकि == दो Values की तुलना करने के लिए।

प्रश्न 4. // और / में क्या अंतर है?

/ सामान्य Division करता है और Float परिणाम देता है, जबकि // Floor Division करके पूर्णांक भाग देता है।

प्रश्न 5. in Operator का उपयोग कहाँ होता है?

किसी List, Tuple, String, Set या Dictionary में Value की उपस्थिति जाँचने के लिए।

 

Quick Revision

  • Operator = Operation करने वाला Symbol
  • Operand = जिस Value पर Operation होता है
  • Arithmetic = + - * / // % **
  • Assignment = = += -= *= /=
  • Comparison = == != > < >= <=
  • Logical = and or not
  • Bitwise = & | ^ ~ << >>
  • Identity = is, is not
  • Membership = in, not in
  • () की Priority सबसे अधिक होती है।

 

अगला अध्याय

Python Input(), Output(), print() Function और Type Casting — इसमें User Input लेना, print() Function, Formatting, Escape Characters, input() Function, Multiple Inputs, Type Casting (int(), float(), str(), bool()) तथा Practical Programs को विस्तार से सीखेंगे।

 

निष्कर्ष (Conclusion)

Python Operators की पूरी जानकारी हिंदी में। Arithmetic, Assignment, Comparison, Logical, Bitwise, Identity, Membership Operators, Operator Precedence और Practical Examples सहित विस्तृत गाइड।