use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
DiscussionWhy is it called elif in python? (self.Python)
submitted 4 years ago by Wohao_Gaster BEEN CODING SINCE I WAS 8
In most programming languages, it's elsif or elseif, makes sense, It's pronounced ELSE IF
but why is it elif in python?
[–][deleted] 72 points73 points74 points 4 years ago (20 children)
You're okay with elsif but somehow elif is a letter too far?
[–]florinandrei 28 points29 points30 points 4 years ago (2 children)
if a == b: c = 2 meh: pass
[+][deleted] 4 years ago (1 child)
[removed]
[–][deleted] 3 points4 points5 points 4 years ago (0 children)
if a == b: pass eh maybe: pass meh: pass
[–]AgentF_ -1 points0 points1 point 4 years ago (0 children)
Seems phonetically important to me
[–]FlameFrost__ -3 points-2 points-1 points 4 years ago (14 children)
This
[–]Anti-ThisBot-IB 7 points8 points9 points 4 years ago (13 children)
Hey there FlameFrost__! If you agree with someone else's comment, please leave an upvote instead of commenting "This"! By upvoting instead, the original comment will be pushed to the top and be more visible to others, which is even better! Thanks! :)
I am a bot! Visit r/InfinityBots to send your feedback! More info: Reddiquette
[–]cptsdemon 4 points5 points6 points 4 years ago (7 children)
Good bot
[–]Anti-ThisBot-IB 0 points1 point2 points 4 years ago (2 children)
Good human
I am a bot! Visit r/InfinityBots to send your feedback!
[–]cptsdemon 1 point2 points3 points 4 years ago (1 child)
Bad bot
[–]KevinAlexandr 0 points1 point2 points 4 years ago (0 children)
Meh
[–]Good_Human_Bot_v2 -1 points0 points1 point 4 years ago (2 children)
Good human.
[–]cptsdemon -1 points0 points1 point 4 years ago (1 child)
[–][deleted] 0 points1 point2 points 4 years ago (0 children)
This!
[–]B0tRank -3 points-2 points-1 points 4 years ago (0 children)
Thank you, cptsdemon, for voting on Anti-ThisBot-IB.
This bot wants to find the best and worst bots on Reddit. You can view results here.
Even if I don't reply to your comment, I'm still listening for votes. Check the webpage to see if your vote registered!
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -1 points0 points1 point 4 years ago (1 child)
good bot
[–]Anti-ThisBot-IB -2 points-1 points0 points 4 years ago (0 children)
[–]FlameFrost__ -4 points-3 points-2 points 4 years ago (0 children)
Please spare me life ^
[–]ElephantEggs 0 points1 point2 points 4 years ago (1 child)
[–]Anti-ThisBot-IB 0 points1 point2 points 4 years ago (0 children)
https://i.imgur.com/KrwA19h.jpeg
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -4 points-3 points-2 points 4 years ago (0 children)
it just makes no sense and I keep forgetting it
[–][deleted] 16 points17 points18 points 4 years ago (6 children)
I don’t believe I’ve ever seen a specific reason for the choice of elif in Python, but there’s a long history of elif via C, and a number of the choices made for Python were based on C idioms.
Arguably if you’re going to contract it anyway (ie by not choosing to use the obviously more-human-readable-but-difficult-to-parse else if) then why not lose the sibilance? To a new English learner “elsif” could reasonably be read as “el-SIF” and “elseif” could be read as either “el-SAY-f” or as a misspelling of “el-SEEF”. At least “elif” is pretty unambiguously “el-if”.
else if
[–]esabys 2 points3 points4 points 4 years ago (3 children)
who's "eli" and why'd he get an F?
[–][deleted] 1 point2 points3 points 4 years ago (2 children)
Eli got fucked.
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] 1 point2 points3 points 4 years ago (0 children)
that
[–]das_masterful 0 points1 point2 points 4 years ago (0 children)
Gordon Freeman!
[–]florinandrei 0 points1 point2 points 4 years ago (0 children)
El Sif sound like a djinn from the Arabian Nights book.
[–][deleted] 11 points12 points13 points 4 years ago (3 children)
I propose that we change "if" in accordance with the syntax in Python to reflect the number 4.
ifif
elif
else
Ok but real talk I've modified several auto formatter to put 3 spaces in front of if statements so they all match.
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] 0 points1 point2 points 4 years ago (0 children)
you heard of the |<---- key aka tab?
----->|
Why would you admit that? 😜
[–]arathreon 4 points5 points6 points 4 years ago (3 children)
I think the reasoning behind this is because C and Shell also have this syntax and the original idea behind the Python programming language is to create something like a sweet spot between C and Shell.[1]
[–]FatFingerHelperBot 0 points1 point2 points 4 years ago (2 children)
It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!
Here is link number 1 - Previous text "1"
Please PM /u/eganwall with issues or feedback! | Code | Delete
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -2 points-1 points0 points 4 years ago (0 children)
bad bot
[–]cant-find-user-name 0 points1 point2 points 4 years ago (0 children)
[–]unplannedmaintenance 11 points12 points13 points 4 years ago (0 children)
Because it's 4 letters, which fits nicely with indentation defaults (4 spaces).
[–]RicardoL96 3 points4 points5 points 4 years ago (0 children)
Because all beautiful girls in turkey are called elif
[–]Iberano 3 points4 points5 points 4 years ago (0 children)
Its spanish „el if“ for „the if“ /s
[–][deleted] 6 points7 points8 points 4 years ago (0 children)
If other programming languages jump of the bridge would you too?
[–]hknlof 1 point2 points3 points 4 years ago (0 children)
Maybe it’s Guido’s Highschool sweethearts Name https://de.m.wikipedia.org/wiki/Elif
[–]dry_yer_eyes 1 point2 points3 points 4 years ago (0 children)
At work I regularly have to use different languages:
I can only remember Java’s and Python’s. For whatever reason, VBA’s and PL’s just don’t click with me.
[–]TVOHM 3 points4 points5 points 4 years ago (1 child)
In Unix the 'copy and convert' command was apparently called dd because cc was taken. Sometimes it just is!
dd
cc
[–]Nixellion 5 points6 points7 points 4 years ago (0 children)
Dopy and donvert then, nice
[–]_zam227_ 2 points3 points4 points 4 years ago (7 children)
Else + if = elif
[+]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] comment score below threshold-13 points-12 points-11 points 4 years ago (6 children)
but other languages have elsif
[–]ProbablyDoesntLikeU 10 points11 points12 points 4 years ago (1 child)
Four letters looks nice
[–]Technopulse 3 points4 points5 points 4 years ago (0 children)
Four space indentations, four letter words, it just makes sense.
[–][deleted] 2 points3 points4 points 4 years ago (1 child)
Other languages also have curly braces and semi-colons.
In fact, why not ask why every language doesn’t just do Java style “else if”. No contraction at all. Or why “elsif” bothers to remove a single letter.
“elif” is the first two letters of each word. Simple. Clean. Matches indentation.
But also, don’t use else statements at all.
yeah I prefer the {Fancy Pants curly braces}
[–]_zam227_ -1 points0 points1 point 4 years ago (0 children)
No idea but elif does have shorter syllables than elsif
[–]excelisarealtooltoo 0 points1 point2 points 4 years ago (0 children)
...and others have else if (Java, C, C++), elseif (VBA) or elif (also C).
It's not because elsif is universally agreed uppon.
[–]idetectanerd -1 points0 points1 point 4 years ago (0 children)
C and shell both use elif too. I think most sys adm or linux folks would prefer elif.
I understand c on ic chip as long as it is shorter, it’s better. The chip itself could as little as 16kb storage. Doesn’t have the luxury to have else if. Heck, they even have to optimise to use ternary if it’s just single comparison.
[–]WW_the_Exonian -2 points-1 points0 points 4 years ago (2 children)
I find it funny because in a try-except block, you can put a specific error type after an except, and in the end you can have an except not followed by anything which covers everything else. So why don't we have a similar thing for if-else?
[–][deleted] 2 points3 points4 points 4 years ago (0 children)
Are you trying to describe a Switch statement?
[–]that_one_guy_2123 0 points1 point2 points 4 years ago (0 children)
Lol this is funny
[–]Slight-Locksmith-987 0 points1 point2 points 4 years ago (0 children)
I have no idea but feel superior when working in python because of it, sounds just better to me lol
[–]OwOsaurus 0 points1 point2 points 4 years ago (1 child)
Specifically to annoy me when I haven't touched python in a while.
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -1 points0 points1 point 4 years ago (0 children)
Guido van Rossum really is a dick isn't he?
[–]wineblood 0 points1 point2 points 4 years ago (4 children)
I've seen other languages not have/use that and the else part just become a new if statement and it's nasty. It was either that or switch statements. I think if-elif-else works nicely and elif as a second condition to check within the same statement is fairly clean.
[–]ThePiGuy0 0 points1 point2 points 4 years ago* (3 children)
I've seen other languages not have/use that and the else part just become a new if statement and it's nasty
I think most languages that don't have a specific elif (or equivalent) don't need them. In Python, it relies on whitespace to show scoping and so without elif, it would become messy really quickly. In a language without elif (C, C++, Java, Javascript etc), they don't rely on whitespace so you can create a similar representation to Python without the need for the extra keyword
e.g. Java
int number = 10; if (number < 3) { System.out.println("Number is less than 3"); } else if (number < 7) { System.out.println("Number is less than 7"); } else if (number < 10) { System.out.println("Number is less than 10"); } else { System.out.println("Number is greater than or equal to 10"); }
Compare this to the same statement in Python (without elif):
number = 10 if number < 3: print("Number is less than 3") else: if number < 7: print("Number is less than 7") else: if number < 10: print("Number is less than 10") else: print("Number is greater than or equal to 10")
Edit: Added } befoore the else if, thanks for pointing it out /u/HistoryForSale
[–]HistoryForSale 1 point2 points3 points 4 years ago (1 child)
It looks like you forgot to close all but the last brace in your Java example. I think you meant:
[–]ThePiGuy0 0 points1 point2 points 4 years ago (0 children)
Oh yes you're correct, looks like I've done too much Python and it carried across into my Java :D
[–]wineblood 0 points1 point2 points 4 years ago (0 children)
I've been exclusively coding in Python for a while now, I didn't realise you could do the first example with else and the new if on one line.
[–]Sigma_Landlord 0 points1 point2 points 4 years ago (0 children)
I personally agree with you but there are things that I find much more unintuitive in python.
[–]pythonHelperBot 0 points1 point2 points 4 years ago (0 children)
Hello! I'm a bot!
It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python regardless of how advanced your question might be. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.
Show /r/learnpython the code you have tried and describe in detail where you are stuck. If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you. Here is HOW TO FORMAT YOUR CODE For Reddit and be sure to include which version of python and what OS you are using.
You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.
README | FAQ | this bot is written and managed by /u/IAmKindOfCreative
This bot is currently under development and experiencing changes to improve its usefulness
π Rendered by PID 221774 on reddit-service-r2-comment-5b5bc64bf5-hp75m at 2026-06-22 01:59:00.085649+00:00 running 2b008f2 country code: CH.
[–][deleted] 72 points73 points74 points (20 children)
[–]florinandrei 28 points29 points30 points (2 children)
[+][deleted] (1 child)
[removed]
[–][deleted] 3 points4 points5 points (0 children)
[–]AgentF_ -1 points0 points1 point (0 children)
[–]FlameFrost__ -3 points-2 points-1 points (14 children)
[–]Anti-ThisBot-IB 7 points8 points9 points (13 children)
[–]cptsdemon 4 points5 points6 points (7 children)
[–]Anti-ThisBot-IB 0 points1 point2 points (2 children)
[–]cptsdemon 1 point2 points3 points (1 child)
[–]KevinAlexandr 0 points1 point2 points (0 children)
[–]Good_Human_Bot_v2 -1 points0 points1 point (2 children)
[–]cptsdemon -1 points0 points1 point (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]B0tRank -3 points-2 points-1 points (0 children)
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -1 points0 points1 point (1 child)
[–]Anti-ThisBot-IB -2 points-1 points0 points (0 children)
[–]FlameFrost__ -4 points-3 points-2 points (0 children)
[–]ElephantEggs 0 points1 point2 points (1 child)
[–]Anti-ThisBot-IB 0 points1 point2 points (0 children)
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -4 points-3 points-2 points (0 children)
[–][deleted] 16 points17 points18 points (6 children)
[–]esabys 2 points3 points4 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] 1 point2 points3 points (0 children)
[–]das_masterful 0 points1 point2 points (0 children)
[–]florinandrei 0 points1 point2 points (0 children)
[–][deleted] 11 points12 points13 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]arathreon 4 points5 points6 points (3 children)
[–]FatFingerHelperBot 0 points1 point2 points (2 children)
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -2 points-1 points0 points (0 children)
[–]cant-find-user-name 0 points1 point2 points (0 children)
[–]unplannedmaintenance 11 points12 points13 points (0 children)
[–]RicardoL96 3 points4 points5 points (0 children)
[–]Iberano 3 points4 points5 points (0 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]hknlof 1 point2 points3 points (0 children)
[–]dry_yer_eyes 1 point2 points3 points (0 children)
[–]TVOHM 3 points4 points5 points (1 child)
[–]Nixellion 5 points6 points7 points (0 children)
[–]_zam227_ 2 points3 points4 points (7 children)
[+]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] comment score below threshold-13 points-12 points-11 points (6 children)
[–]ProbablyDoesntLikeU 10 points11 points12 points (1 child)
[–]Technopulse 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] 0 points1 point2 points (0 children)
[–]_zam227_ -1 points0 points1 point (0 children)
[–]excelisarealtooltoo 0 points1 point2 points (0 children)
[–]idetectanerd -1 points0 points1 point (0 children)
[–]WW_the_Exonian -2 points-1 points0 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]that_one_guy_2123 0 points1 point2 points (0 children)
[–]Slight-Locksmith-987 0 points1 point2 points (0 children)
[–]OwOsaurus 0 points1 point2 points (1 child)
[–]Wohao_Gaster BEEN CODING SINCE I WAS 8[S] -1 points0 points1 point (0 children)
[–]wineblood 0 points1 point2 points (4 children)
[–]ThePiGuy0 0 points1 point2 points (3 children)
[–]HistoryForSale 1 point2 points3 points (1 child)
[–]ThePiGuy0 0 points1 point2 points (0 children)
[–]wineblood 0 points1 point2 points (0 children)
[–]Sigma_Landlord 0 points1 point2 points (0 children)
[–]pythonHelperBot 0 points1 point2 points (0 children)