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.
🌐
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 ...
🌐
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.
🌐
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.
🌐
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 …
🌐
X
x.com › RealBenjizo › status › 2034292168538444234 › photo › 1
Benjamin Bennett Alexander on X: "🛑Stop Using Python Code to Build Pyramids or Arrows If you have too many layers of if statements stacked inside each other, you are no longer writing readable and easy-to-maintain code; you are building a pyramid. 😄 Look at this: def process_user(user_data): if https://t.co/TxlMToSPkB" / X
Stop Using Python Code to Build Pyramids or Arrows If you have too many layers of if statements stacked inside each other, you are no longer writing readable and easy-to-maintain code; you are building a pyramid. Look at this: def process_user(user_data): if user_data: if 'name' in user_data: if user_data['name']: if 'email' in user_data: if validate_email(user_data['email']): return save_user(user_data) else: return "Invalid email" else: return "Email missing" else: return "Name empty" else: return "Name missing" else: return "No data" This is called the "Arrow Anti-Pattern" or "Pyramid of Doom."
Find elsewhere
🌐
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.
🌐
Substack
dataopsleadership.substack.com › p › where-openclaw-and-claude-code-fit
Where OpenClaw and Claude Code fit into the data stack for data leaders
5 days ago - import os import json from typing import List, Dict, Any from fastapi import FastAPI, WebSocket, WebSocketDisconnect from fastapi.responses import HTMLResponse from anthropic import AsyncAnthropic import uvicorn # ------------------------------------------------------------ # Config # ------------------------------------------------------------ ANTHROPIC_API_KEY = os.getenv(”ANTHROPIC_API_KEY”) if not ANTHROPIC_API_KEY: raise RuntimeError(”Set ANTHROPIC_API_KEY in your environment.”) MODEL = os.getenv(”CLAUDE_MODEL”, “claude-opus-4-6”) MAX_TOKENS = int(os.getenv(”CLAUDE_MAX_T
🌐
Vaia
vaia.com › if else in python
If Else in Python: Statement & Example | Vaia
In Python, the "if else" statement is a fundamental control structure used for decision making, allowing the program to execute a block of code if a condition is true (using "if") and an alternative block if the condition is false (using "else").
🌐
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.
🌐
CodingBat
codingbat.com › python
CodingBat Python
Welcome to Codingbat. See help for the latest · Python HelpPython Example CodePython StringsPython ListsPython If BooleanCode Badges
🌐
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.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › python-if-else-statement
Python If-Else Statements: Syntax, Examples & Real-world Applications
August 14, 2025 - The if-else statement in Python is a conditional statement that executes a block of code when a specified condition evaluates to True and a different block when the condition is 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.
🌐
Home Assistant
home-assistant.io › docs › configuration › templating
Templating - Home Assistant
If the value is not listed here, the function returns the default value, or if omitted raises an error. This function is intended to be used on states of binary sensors, switches, or similar entities, so its behavior is different from Python’s built-in bool conversion, which would consider values like "on", "off", and "unknown" all to be true, but "" to be false; if that is desired, use not not value or a similar construct instead.