Elif Statements

*Quick Post

An Elif statement stands for an else if statement. The elif statements are typically used between the if and else statements. So if an if statement evaluates to be false then the elif will then be evaluated. If the elif statement then proceeds to be false then the else statement will be evaluated. A series of elif statements usually has a final else statement, which is evaluated when none of the previous if or elif statements are true.

[Console]

Num = 7

If num == 5:

print(“Number is 5”)

Elif num == 11:

print(“Number is 11”)

Elif num == 7

print(“Number is 7”)

Else:

print(“Number is not 5, 11 or 7)

=====

[Interpreter]

Number is 7

As can be seen in the example above, the interpreter will evaluate the code from the if to elif then to the else statement until one of the statements rings true. The code for that statement is then interpreted.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s