Python Python Basics Types and Branching If, Else and Elif

Chinwe Nwadiora
Chinwe Nwadiora
1,832 Points

Must elif code block come before else code block, or is the order of elif and else interchangeable?

Must elif code block come before else code block, or is the order of elif and else interchangeable?

3 Answers

Steven Parker
Steven Parker
170,254 Points

A conditional series always starts with an "if". An "else" is optional, but it must always be last. In between you may have (also optional) any number of "elif" statements.

Chinwe Nwadiora
Chinwe Nwadiora
1,832 Points

Perfect, and very good to know. Thanks for the quick response, Steven!

I had the same question. Thanks!