Python Boolean Operators || boolean operators in python, boolean operators in python in hindi

Home 👉 O level 👉 Python 👉 Unit 4


Boolean Operators in Python

इन ऑपरेटर्स का उपयोग कम्पाउंड कंडीशन्स (एक शर्त जो दो या अधिक शर्तों को मिलाकर बना हो) को बनाने के लिए किया जाता है। जब बूलियन ऑपरेटर्स बूल टाइप के मान जैसे True या False पर ऑपरेशन करते हैं तो बूल टाइप का रिजल्ट देते हैं। 

इन ऑपरेटर्स का उपयोग कम्पाउंड कंडीशन्स (एक शर्त जो दो या अधिक शर्तों को मिलाकर बना हो) को बनाने के लिए किया जाता है। जब बूलियन ऑपरेटर्स बूल टाइप के मान जैसे True या False पर ऑपरेशन करते हैं तो बूल टाइप का रिजल्ट देते हैं। पायथन में बूलियन ऑपरेटरों का उपयोग बूलियन मानों (सही और गलत) पर तार्किक क्रियाएं करने के लिए किया जाता है। पायथन में तीन मुख्य बूलियन ऑपरेटर हैं: `और`, `या`, और `नहीं`। इन बूलियन ऑपरेटरों का उपयोग अक्सर सशर्त बयानों, लूपों और अन्य स्थितियों में किया जाता है जहां आपको कुछ शर्तों की सच्चाई या झूठ के आधार पर निर्णय लेने की आवश्यकता होती है। वे आपके पायथन प्रोग्रामो में अधिक जटिल और सार्थक तर्क बनाने में आपकी सहायता करते हैं।

These operators are used to create compound conditions (a condition made up of two or more conditions). Boolean operators return a result of bool type when they operate on values of bool type, such as True or False.

Boolean operators return a result of bool type when they operate on values of bool type, such as True or False. Boolean operators in Python are used to perform logical operations on boolean values (True and False). Python has three main boolean operators: `and`, `or`, and `not`. These boolean operators are often used in conditional statements, loops, and other situations where you need to make decisions based on the truth or falsity of certain conditions. They help you create more complex and meaningful logic in your Python programs.

  • Logical And ( and )
  • Logical Or ( or )
  • Logical Not ( not )

Logical And (and):-

    यह ऑपरेटर दोनों साइड की वैल्यू के True होने पर परिणाम True देता है अन्यथा False देता है। पायथन में, लॉजिकल AND ऑपरेटर को `and` द्वारा दर्शाया जाता है। इसका उपयोग दो या दो से अधिक शर्तों को संयुक्त करने के लिए किया जाता है, और यदि सभी शर्तें  'सही' पर मूल्यांकन करती हैं, तो यह 'सही' लौटाता है, अन्यथा, यह 'गलत' लौटाता है। आप अपने कोड में अधिक जटिल स्थितियाँ बनाने के लिए `and` ऑपरेटर का उपयोग कर सकते हैं, विशेष रूप से सशर्त कथनों में (उदाहरण के लिए, यदि कथन) या अपने प्रोग्रामो में निर्णय लेते समय।


`and` ऑपरेटर कैसे काम करता है:
  • `True and True` का मूल्यांकन `True` से होता है।
  • `True and False` का मूल्यांकन `False` से होता है।
  • `False and True` का मूल्यांकन `False` से होता है।
  • `False and False` का मूल्यांकन `False` से होता है।

    This operator returns True if the values on both sides are True, otherwise it returns False. In Python, the logical AND operator is denoted by `and`. It is used to combine two or more conditions or expressions, and it returns `True` if all of the conditions or expressions evaluate to `True`, otherwise, it returns `False`. You can use the `and` operator to create more complex conditions in your code, especially in conditional statements (e.g., if statements) or while making decisions in your programs.


Here's how the `and` operator works:

  • `True and True` evaluates to `True`.
  • `True and False` evaluates to `False`.
  • `False and True` evaluates to `False`.
  • `False and False` evaluates to `False`.


syntax: condition1 and condition2
example: 2 > 1 and 1 < 2
result: True

इस ऑपरेटर के दोनों साइड की वैल्यू यदि बूलियन वैल्यूज (True / False) में नहीं है तो ये दूसरे तरह कार्य करते हैं। जैसे-

If the value of both the sides of this operator is not in Boolean values (True / False) then they work in the other way. As-


syntax: x and y
example: 2 and 1
result: 1

HINT:

यदि x False है तो परिणाम y होगा अन्यथा परिणाम x होगा 
If x is False then the result will be y otherwise the result will be x.


Note: 
कोई भी नॉन-जीरो वैल्यू True मानी जाती है तथा निम्न मान False माने जाते हैं-
Any non-zero value is considered as True and the following values are considered as False-
0, 0.0, 0j, "", '', [], (), {}, None, False

"" और '' एम्प्टी स्ट्रिंग कहलाते हैं जिनमें कोई अक्षर नहीं है।
"" and '' are called empty strings which do not contain any characters.

[], (), {} एम्प्टी सीक्वेंस कहलाते हैं जिनमें कोई वैल्यू नहीं है। 
[], (), {} are called empty sequences which do not contain any value.

Logical Or (or):-

    यह ऑपरेटर दोनों साइड की वैल्यू के False होने पर परिणाम False देता है अन्यथा True देता है। पायथन में, लॉजिकल OR ऑपरेटर को कीवर्ड `or` द्वारा दर्शाया जाता है। इसका उपयोग दो या दो से अधिक शर्तों को संयोजित करने के लिए किया जाता है और यदि कम से कम एक शर्त 'True' है तो 'True' लौटाता है। यदि सभी शर्तें `गलत` हैं, तो यह `False` लौटाता है।

    This operator returns False if both sides of the value are False, otherwise it returns True. In Python, the logical OR operator is represented by the keyword `or`. It is used to combine two or more conditions and returns `True` if at least one of the conditions is `True`. If all the conditions are `False`, it returns `False`. 


syntax: condition1 or condition2
example: 2 > 1 or 1 < 2
result: True

इस ऑपरेटर के दोनों साइड की वैल्यू यदि बूलियन वैल्यूज (True / False) में नहीं है तो ये दूसरे तरह कार्य करते हैं। जैसे-

If the value of both the sides of this operator is not in Boolean values (True / False) then they work in the other way. As-


syntax: x or y
example: 2 or 1
result: 2

HINT:
यदि x True है तो परिणाम x होगा अन्यथा परिणाम y होगा 
If x is True then the result will be x otherwise the result will be y.


Logical Not (not):-

    यह एक यूनरी ऑपरेटर है जो सिंगल वैल्यू पर कार्य करता है तथा True को False में तथा False को True में बदलता है। पायथन में, लॉजिकल NOT ऑपरेटर को कीवर्ड `not` द्वारा दर्शाया जाता है। इसका उपयोग बूलियन एक्सप्रेशन के तार्किक मान को उलटने के लिए किया जाता है। जब आप बूलियन मान या एक्सप्रेशन पर `not` लागू करते हैं, तो यह विपरीत मान लौटाएगा। यदि एक्सप्रेशन 'True' है, तो 'not' इसे 'False' बना देगा, और यदि एक्सप्रेशन 'False' है, तो 'not' इसे 'True' बना देगा। `not` ऑपरेटर सशर्त बयानों, लूप और अन्य नियंत्रण संरचनाओं में स्थितियों को नकारने के लिए उपयोगी है।

    It is a unary operator which operates on a single value and converts True to False and False to True. In Python, the logical NOT operator is represented by the keyword `not`. It is used to reverse the logical value of a Boolean expression. When you apply `not` to a Boolean value or expression, it will return the opposite value. If the expression is `True`, `not` will make it `False`, and if the expression is `False`, `not` will make it `True`. The `not` operator is useful for negating conditions in conditional statements, loops, and other control structures.


syntax: not condition
example: not 2 > 3
result: True



NEXT:-

---END---

Comments

Post a Comment