I’d like to suggest adding support for else if or elseif as optional alternatives to elif. In many other languages, those forms are more familiar and feel more natural to read and write.
While elif is concise, allowing the more explicit forms could improve readability for developers coming from other language backgrounds without breaking existing code.
else if is not more explicit than elif, as it introduces no additional information, nor does it remove any ambiguity. If anything, it introduces a new form of confusion, as else might be followed by if, but not by any other keyword (unless you’re also proposing things like else try: and such).
The two-word form makes sense in C-like languages because it is exactly equivalent to having an else clause that contains an if statement; but in Python, that would require else: on one line and if ...: indented underneath it, hence the combined keyword elif. Since it has to function as a single keyword, there is no value in having a space in it.
Hey thanks for clarifying. It makes sense to not jam in two control flow keywords since they both mean different things. elif feels unnatural but I get the design choice. I think elseif instead of elif would be good too. But why write two extra letters, right?
When I first came across elif I wasn’t sure I liked it, but then I realised that it has the advantage that it’s distinct from “else if” when spoken, which, for some languages such as Modula-2, is important if you’re using text-to-speech or speech recognition because of the language’s syntax. In C or Pascal, it’s fine, but in Modula-2, it’s not.
There are other cases where Guido (van Rossum, the language’s designer) favored brevity over instant familiarity at first sight, like def and del. As learning curves go, these are very shallow, and the millionth time you type one of them you actually will give some value to not needing “two extra characters” .
I am teaching Python to people where english is not their primary language, and I would love for Python to evolve more towards comprehensibility - I support the overall goal of “Python is pseudocode which runs”, and being a great introduction language. I have been programming 20+ years, and these “elif”-type shortcuts have always frustrated me. Thanks for proposing the idea, and I hope it (and similar ideas) gain traction.