Help on explaining elif statements please?


#1

very confused on elif statements, is it the same as if else? because i understand that.


#2

@plp000,
google search
if elif site:python.org
= https://docs.python.org/2/reference/compound_stmts.html
=quote=

7.1. The if statement

The if statement is used for conditional execution:
if_stmt ::=  "if" expression ":" suite
             ( "elif" expression ":" suite )*
             ["else" ":" suite]

It selects exactly one of the suites by evaluating the expressions one by one until one is found to be true (see section Boolean operations for the definition of true and false); then that suite is executed (and no other part of the if statement is executed or evaluated). If all expressions are false, the suite of the else clause, if present, is executed.

=end-quote=

example:

test = True
if test == True:
    #indentation
    print "the variable =test= is True"
elif test == False:
    print "the variable =test= is False"
else:
    print "i am only testing =test= for True or False and NOT for " + str(test)