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