Logical/Boolean Operators:-
लॉजिकल ऑपरेटर जो है वह Boolean expressions को compare करता है तथा Boolean result रिटर्न करता है।
पायथन में मुख्य रूप से तीन प्रकार के लॉजिकल ऑपरेटर होते है –
- and
- or
- not
and Operator:
logical and operator binary operator होता है। अर्थात इसे कार्य करने के लिए 2 operand की आवश्यकता होती है। यदि सभी condition सही होते हैं, तो logical and operator true result देता है।
Truth table of and operator
a |
b |
a and b |
Result |
Example |
Description |
0 |
1 |
0 |
False |
x < 5 and x < 10 |
यदि दोनों statements सही है तो यह true return करेगा |
0 |
0 |
0 |
False |
||
1 |
0 |
0 |
False |
||
1 |
1 |
1 |
True |
Note:-
- Unary Operator:- work with one operand.
- Binary Operator:- work with two operand.
- Ternary Operator:- work with three operand.
or Operator:
यह operator binary operator होता है। यह operator true result देता है, यदि एक भी condition सही है तो। जब सभी condition गलत होते हैं तो result false होता है।
Truth table of or operator
a |
b |
a or b |
Result |
Example |
Description |
0 |
1 |
1 |
True |
x < 5 or x < 4 |
यदि दोनों statements में से एक statements भी सही है तो यह true return करेगा। |
0 |
0 |
0 |
False |
||
1 |
0 |
0 |
True |
||
1 |
1 |
1 |
True |
not Operator:
logical not operator unary operator होता है, यह true को false और false को true में बदलता है। इसमें एक operand की जरूरत होती है।
Operand |
Result |
True |
False |
False |
True |
Logical/Boolean Operators:-
Logical operator compares Boolean expressions and returns a Boolean result.
There are mainly three types of logical operators in Python –
- and
- or
- not
and Operator:
logical and operator is binary operator. That means it requires 2 operands to function. If all the conditions are true, then the logical AND operator returns true result.
Truth table of and operator
a |
b |
a and b |
Result |
Example |
Description |
0 |
1 |
0 |
False |
x < 5 and x < 10 |
If both the statements are true then it will return true |
0 |
0 |
0 |
False |
||
1 |
0 |
0 |
False |
||
1 |
1 |
1 |
True |
Note:-
- Unary Operator:- work with one operand.
- Binary Operator:- work with two operand.
- Ternary Operator:- work with three operand.
or Operator:
This operator is a binary operator. This operator returns true result if any one condition is true. When all the conditions are false then the result is false.
Truth table of or operator
a |
b |
a or b |
Result |
Example |
Description |
0 |
1 |
1 |
True |
x < 5 or x < 4 |
It will return true if either of the two statements is true. |
0 |
0 |
0 |
False |
||
1 |
0 |
0 |
True |
||
1 |
1 |
1 |
True |
not Operator:
Logical not operator is a unary operator, it changes true to false and false to true. It requires one operand.
Operand |
Result |
True |
False |
False |
True |