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

else


Related:

 Examples

 
 
if age > 16:
print "You can drive!" elif age == 16: print "You just made it!" else: print "Nope, get a skateboard!"

 Description        

 
Used along with an if statement, code under the else statement is executed only when the condition in the if statement is false.

 Syntax

 
 
if condition:
    statement(s)
else:
    statement(s)

 Parameters

 
condition - an expression which can be evaluated to either true or false

statement - the code to execute depending on whether the condition is true or false

 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.

>>> temp = 20

>>> if temp > 25:

...   print "it is hot"

... else:

...   print "nope, not too hot!"

... 

nope, not too hot!





Comments