November 2017
Beginner to intermediate
204 pages
5h 23m
English
The combination of a single clause header and a code block is called a clause. Some compound statements, including the if statement, are able to have multiple clauses.
The elif clause (short for else if) follows directly after the initial if clause. If the condition of the if clause is not met, the elif clause will check to see whether a second condition is met, and conditionally run another block of code. The following program uses an elif clause to check whether it is cloudy when it is not sunny:
isSunny = FalseisCloudy = Trueif isSunny: print('Nice Weather!')elif isCloudy: print('Might Rain Soon!')
An if statement must start with an if clause, but there can be an indefinite number of elif clauses chained one after ...
Read now
Unlock full access