Important Notice:

Logical Operators

Logical Operators

29 views 2 min read

Logical Operators (लॉजिकल ऑपरेटर) :-

Logical Operators (लॉजिकल ऑपरेटर) वे Operators हैं जिनका उपयोग दो या दो से अधिक conditions या expressions को जोड़ने (Combine) और उनके बीच Logical Decision लेने के लिए किया जाता है। इनका result हमेशा Boolean value True या False होता है।

Python में Logical Operators का उपयोग मुख्य रूप से multiple conditions को check करने के लिए किया जाता है, जैसे कि सभी conditions True हैं या कोई एक condition True है या नहीं।

English

Logical Operators are used to combine two or more conditions or expressions and perform logical operations between them. They always return a Boolean value True or False as a result.

These operators are commonly used in conditional statements, loops, and decision-making programs.

Syntax -

condition1 operator condition2
 
Example -
 
a = 20
b = 10
print(a > 15 and b < 15)
 
Output -
 
True
 
यहाँ दोनों conditions True हैं, इसलिए result True है।
 
Types of Logical Operators (लॉजिकल ऑपरेटर्स के प्रकार) :-

Python में Logical Operators के मुख्य 3 Types होते हैं:

  1. AND Operator (and) – तथा / और
  2. OR Operator (or) – या
  3. NOT Operator (not) – नहीं / उल्टा
1. Logical AND Operator (and) :-

The Logical AND Operator (and) is used to check whether both conditions are True or not.

Logical AND Operator (and) का उपयोग यह जाँचने के लिए किया जाता है कि दोनों conditions True हैं या नहीं।

यदि दोनों conditions True होती हैं, तो result True होता है। यदि किसी एक condition का result False होता है, तो result False होता है।

Syntax -
result = condition1 and condition2
 
Example -
a = 20
b = 10
print(a > 15 and b < 15)
 
Output -
True
 
यहाँ: 
a > 15  → True
b < 15  → True
दोनों conditions True हैं, इसलिए and का result True है।
 
2. Logical OR Operator (or) :-

The Logical OR Operator (or) is used to check whether at least one condition is True.

Logical OR Operator (or) का उपयोग यह जाँचने के लिए किया जाता है कि कम से कम एक condition True है या नहीं।

यदि किसी एक condition का result True होता है, तो पूरा result True होता है। केवल तब result False होता है जब सभी conditions False हों।

Syntax -
result = condition1 or condition2
 
Example -
a = 20
b = 10
print(a > 15 or b > 20)
 
Output -
True
 
यहाँ: 
a > 15  → True
b > 20  → False
एक condition True है, इसलिए or का result True है।
 
 
3. Logical NOT Operator (not) :-

The Logical NOT Operator (not) is used to reverse or invert the Boolean result of a condition.

Logical NOT Operator (not) का उपयोग किसी condition के Boolean result को उलटने (Reverse) के लिए किया जाता है।

यदि condition का result True है, तो not उसे False कर देता है।
यदि condition का result False है, तो not उसे True कर देता है।

Syntax -
result = not condition
 
Example -
a = 20
print(not(a > 10))
 
Output -
False
 
यहाँ: 
a > 10  → True
not True → False
इसलिए result False है।

 

Related Notes