Languages with C-type syntax get else if for free without doing it at all.
The reason is that in these syntactic control structures, they simply work with the following statement, which can be a compound expression enclosed in curly braces, if necessary (for example, { x += 1; y += 1 } ).
This means that after you have implemented if and else , else if just disappears from the grammar of the language, naturally, for free, without any further implementation efforts. To understand why, look at this:
if (condition) { if_body(); } else if (another_condition) { else_if_body(); } else { else_body(); }
It looks like an if with attached else if and else , each of which is applied to the compound statement. But actually it is not. In fact, these are two separate if , each of which has exactly one else case; the second if is inside the else body of the first if .
else if { ... } really parsed as else applied to the next statement, which is the if (applied to the compound expression { else_if_body(); } . Then the final else bound to the previous previous if , which is the second.
Here the same is written more according to how it was analyzed 1 :
if (condition) { if_body(); } else { if (another_condition) { else_if_body(); } else { else_body(); } }
But it turns out that if the language directly implemented else if as a first-class option for if , it will behave exactly like the second independent if inside else first! Thus, there is no need to worry about implementing else if at all; language developers get an else if for free with this syntax style as soon as they implement if and else .
Python syntax does not allow this freebie.
C-style syntax programmers can think in terms of else if , although the language has an if only with zero or one else , but only because they can write code, like my first example, which is formatted in a way that is different from the human reader, than with the compiler.
Python, OTOH, uses padding to indicate the block structure, which makes the block structure look the same with the human reader, as with interpreter 2 . After you received if and else in the Python style syntax, programmers could still write code that behaves identically to else-if by placing the second if inside the else first. But it looks like this:
if condition: if_body() else: if another_condition: else_if_body() else: else_body()
It looks ugly and much more difficult to think in terms than the else-if chain when you get more than 1 or 2 else-ifs. Therefore, it is worth adding an explicit language function to restore the ability to think in terms of else-if. Even though it technically makes the language more complex, it actually makes thinking from the point of view of the language simpler, so this is a good complexity; with a manually created chain of nested if inside else reader must manually read the entire code and make sure that every else except the last contains exactly one if and nothing else to conclude that the whole sequence is equivalent to a linear chain of conditions checked in order, with some code to perform the first check, which succeeds.
So then. We have seen that languages with C-type syntax can also be used with else if , because they get it for free. This is the reason why it exists. Languages with syntax like Python must explicitly do something to get a construct that can be used as else-if. Why did they choose elif ? It is arbitrary; you will actually have to ask the people who made the decision.
However, Python did not invent elif ; it was in other languages long before Python existed. Therefore, I would suggest that when they had to implement the explicit else-if construct, they simply chose the one that programmers are already familiar with.
1 Technically, that’s the way people who REALLY take seriously the use of braces with control structures should write their code .;)
2 You can, of course, create counter-examples for this, but this is a general idea of syntax based on indentation.