In python "else if" is spelled "elif".
Also, you need a colon after the elif and the else.

Simple answer to a simple question. I had the same problem, when I first started (in the last couple of weeks).

So your code should read:

def function(a):
    if a == '1':
        print('1a')
    elif a == '2':
        print('2a')
    else:
        print('3a')

function(input('input:'))
Answer from Frames Catherine White on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_conditions.asp
Python If Statement
Python can evaluate many types of values as True or False in an if statement. Zero (0), empty strings (""), None, and empty collections are treated as False. Everything else is treated as True.
Discussions

Help! If / Else statements.
Reformatting your code to what I believe you meant. num = 8941 % 931 # Define if/else condition if (_ _): # Print message below print("The number num is ", _ _) else: # Print another message below print("The number num is ", _ _) One way to think about If/Else statements are making a decision. if (some_condition): # Do something else: # Do something else You can pass in some condition to the if statement - if the condition is true, then it will run whatever is underneath the if statement. If it is not true, then it will run what is under the else statement. I'm not sure exactly what you're trying to accomplish here, but here is a (very) small list of examples of conditions. if a < b - This checks if the variable a is less than b if len(a) == 5 - This checks if the length of a is 5 if a == b - This checks if a is equal to b More on reddit.com
🌐 r/learnpython
9
1
March 12, 2022
Nose alternatives - nose2, pytest or something else?
I used all of them, in Django and non-Django Python apps, and I finally settled on py.test. Its fixtures are really nice, and I love writing tests with assert. More on reddit.com
🌐 r/Python
19
17
December 30, 2015
dumb python question about if statements
You can, but they do different things. a = True b = True if a: print("A!") if b: print("B!") Will print both "A!" and "B!". a = True b = True if a: print("A!") elif b: print("B!") Will only print "A!", because the elif is not taken. More on reddit.com
🌐 r/learnpython
15
0
June 28, 2023
Python 3.10 Match statements are 86% faster than If statements
That's because he's calling isinstance in the first case. When I remove that, the two times are equivalent. When I replace "len(seq) > 0" by "seq", it's faster. When I drop the test and assume the sequence is not empty, it's faster still. E:\dev\MiscPython py tmp.py 0.016316700028255582 0.010650299955159426 E:\dev\MiscPython py tmp.py 0.010991500050295144 0.010603499948047101 E:\dev\MiscPython py tmp.py 0.0087799999746494 0.011524099973030388 E:\dev\MiscPython py tmp.py 0.006842300004791468 0.010922499990556389 More on reddit.com
🌐 r/Python
91
1003
November 15, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-if-else
Python If Else Statements - Conditional Statements - GeeksforGeeks
September 16, 2025 - Nested If..else allows the execution of specific code blocks based on a series of conditional checks. ... i = 10 if i == 10: # First if statement if i < 15: print("i is smaller than 15") # Nested - if statement # Will only be executed if statement ...
🌐
Great Learning
mygreatlearning.com › blog › it/software development › else if python: understanding the nested conditional statements
Else if Python: Understanding the Nested Conditional Statements
October 14, 2024 - The "else if" statement in Python provides a way to handle multiple conditions sequentially. It allows us to specify a series of conditions to be evaluated one after another and execute the corresponding code block when a condition is true.
🌐
Programiz
programiz.com › python-programming › if-elif-else
Python if, if...else Statement (With Examples)
number = 5 # outer if statement if number >= 0: # inner if statement if number == 0: print('Number is 0') # inner else statement else: print('Number is positive') # outer else statement else: print('Number is negative') ... Here's how this program works. ... In certain situations, the if statement can be simplified into a single line. For example, ... This one-liner approach retains the same functionality but in a more concise format. ... Python doesn't have a ternary operator.
🌐
Python documentation
docs.python.org › 3 › tutorial › controlflow.html
4. More Control Flow Tools — Python 3.14.3 documentation
There can be zero or more elif parts, and the else part is optional. The keyword ‘elif’ is short for ‘else if’, and is useful to avoid excessive indentation. An if … elif …
Find elsewhere
🌐
Google
google.com › goto
Python Shorthandf If Else
Python If...Else Tutorial If statement If Indentation Elif Else Shorthand If If AND If OR If NOT Nested If The pass keyword in If
🌐
DEV Community
dev.to › sayandeepmajumdar › python-if-else-statements-a-beginners-guide-with-examples-59fb
Python If-Else Statements: A Beginner's Guide with Examples - DEV Community
July 4, 2023 - If-else statements in Python provide a way to execute different sections of code based on whether a given condition evaluates to true or false.
🌐
freeCodeCamp
freecodecamp.org › news › python-if-else-statement-example
Python If-Else Statement Example
April 10, 2022 - if x < y: print("x is less than y") else: print("x is equal to or greater than y") Note that the fact that Python is a whitespace-sensitive ensures that these if-else statements are easy to read – even when they get nested several layers deep.
🌐
Career Karma
careerkarma.com › blog › python › if else python statements: a step-by-step guide
if else Python Statements: A Step-By-Step Guide | Career Karma
December 1, 2023 - An if else Python statement evaluates whether an expression is true or false. If a condition is true, the “if” statement executes. Otherwise, the “else” statement executes.
🌐
Google
google.com › goto
Conditional Statements in Python(if, elif, else)
May 1, 2024 - The else statement provides a complementary branch to the if statement, allowing us to handle both true and false conditions effectively in our code. Next, we'll explore the elif statement, which further extends our ability to handle multiple ...
🌐
Reddit
reddit.com › r/learnpython › help! if / else statements.
r/learnpython on Reddit: Help! If / Else statements.
March 12, 2022 -

I’m trying to learn python (literal first day) and I’ve ran into a rut.

Please any help and understanding would be fantastic.

1 num= 8941%931 2 3# Define if/else condition 4 if(_ _): 5 #Print message below 6 Print (“The number num is “, _ _ ) 7 else: 8 #print another message below 9 print (“the number num is “, _ _ )

I need help with the ( _ _ ). I’m not sure what to put there.

TIA

🌐
YoungWonks
youngwonks.com › blog › How-to-use-Python-If-Else-statements
What are conditional statements? How to use Python If-Else statements?
August 28, 2022 - When the if statement is true, the on-true statement is executed else the on-false statement if executed. We learned about all the different kinds of conditional statements used in the Python programming language in this tutorial.
🌐
PW Skills
pwskills.com › blog › data analytics › python if else statement: complete overview of conditional statements
Python If Else Statement: Complete Overview Of Conditional Statements
November 4, 2025 - When the if condition satisfies then the code is executed. However, when the if condition does not satisfy then the else condition is executed. The if condition is the beginning of the conditional statement.
🌐
Substack
austinkleon.substack.com › p › unnecessary-obstacles
Unnecessary obstacles - Austin Kleon
2 weeks ago - Oliver Burkeman has a helpful term he calls “unclenching,” which he describes as “a psychological ’move’ that involves relaxing in the midst of anxiety and uncertainty.” He’s been writing really great newsletters on the theme, such as “The freewriting way of life” and “Nobody’s ever ready,” which was about avoiding the anxiety around whether you’ll get “left behind” if you’re not into A.I. Great mantra: “Unclench!” · Pizza night: Watching Monty Python and the Holy Grail was a good excuse to show the boys this 1974 BBC clip of Terry Gilliam on his cutout animation technique.
🌐
W3Schools
w3schools.com › python › python_if_else.asp
Python Else Statement
Python Examples Python Compiler ... isn't caught by the preceding conditions. The else statement is executed when the if condition (and any elif conditions) evaluate to False....
🌐
Inventive HQ
inventivehq.com › home › blog › python if, else, and elif conditional statements: a complete guide
Python if, else, and elif Conditional Statements: A Complete Guide
November 6, 2025 - Practice with real-world examples, ... coding! ... 'if' starts a new conditional check, while 'elif' (short for 'else if') is used to check additional conditions only if the previous conditions were False....
🌐
Real Python
realpython.com › python-conditional-statements
Conditional Statements in Python – Real Python
January 18, 2024 - There is also syntax for branching execution based on several alternatives. For this, use one or more elif (short for else if) clauses. Python evaluates each <expr> in turn and executes the suite corresponding to the first that is true.
🌐
Pydantic
docs.pydantic.dev › latest › concepts › validators
Validators - Pydantic Validation
from typing import Annotated, Any from pydantic import BaseModel, PlainValidator def val_number(value: Any) -> Any: if isinstance(value, int): return value * 2 else: return value class Model(BaseModel): number: Annotated[int, PlainValidator(val_number)] print(Model(number=4)) #> number=8 print(Model(number='invalid')) # (1)!