Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Logical operators in python

  • 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 :
  1. 0
  2. 1
  3. empty string. 
  • Here True means 1 and Flase means 0.      
  • There are three different types of logical operators, they are :
  1. And
  2. or
  3. 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
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.

  1. a=2
  2. b=5
  3. print(a)



  • 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.

  1. x=5
  2. y=10
  3. print(not x==y)
  4. True



This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

Logical operators in python

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×