Knowledge Base‎ > ‎Programming‎ > ‎Python‎ > ‎Python Reference‎ > ‎

Logical Operators - And / Or


Related:

 Examples

 
 
age = 18
date = "2010/10/25"

if age >= 18 and date == "2010/10/25":
  print "go vote for mayor!"

 Description        

 
Logical operators. 

and - requires both sides to be true to evaluate to true

or - requires only one side to be true to evaluate to true

 Syntax

 
 

 Parameters

 

 Interpreter

 Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 

[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> age = 18

>>> date = "2010/10/25"

>>> if age >= 18 and date == "2010/10/25":

...   print "go vote for mayor!"

...

go vote for mayor!

>>> True and True

True

>>> True and False

False

>>> True or True

True

>>> True or False

True

>>> False or False

False

>>>




Comments