- In python, we have the logical operator.
- "Logical operator" used to perform the different logical operations on the value of variables.
- The logical operators are applicable for boolean and non-boolean types.
- Boolean types are:
- True, False
- non-boolean types are :
- 0
- 1
- empty string.
- Here True means 1 and Flase means 0.
- There are three different types of logical operators, they are :
- And
- or
- Not
- And operator: And operator is used when both arguments are True then the result is True.
- syntax: x and y
Example: write a python code for And operator.
1.a=10
2.b=20
3.print(a>30 And b<30)
4.False
- or operator: or operator is used when at least any one of the arguments is true then the result will be True.
- syntax: x or y
Example: Write a python code using the or operator.
- a=2
- b=5
- print(a<3 or b>)
- not operator: not operator is the opposite to the result of an argument, if it is true then the result is False and vice-versa.
- syntax: x not y
Example: write a python code using the not operator.
- x=5
- y=10
- print(not x==y)
- True
No comments