3. Working with text and user input
In Python, any sequence of characters enclosed in quotation marks is called a string. A string can hold a name, a sentence, a phone number written as text, or even an empty space.
Here are some examples:
name = "Almaz"
city = 'Addis Ababa'
greeting = "Selam, how are you?"
phone = "0911-000-000"
The quotation marks tell Python: "everything between these marks is text, not code". You can use single quotes or double quotes — both create strings.
Notice how we stored each string in a variable. A variable is like a labelled box: you put a value inside and recall it later by the label. The = sign does not mean "equal" here — it means "store this value in this box".
Once you store text in a variable, you can print it:
name = "Abebe"
print(name)
This outputs:
Abebe
Notice — no quotation marks in the output! When you print a variable, Python shows its value, not the variable's name.
You can also join (concatenate) strings using the + operator:
first = "Abebe"
last = "Girma"
full = first + " " + last
print(full)
Output:
Abebe Girma
The " " in the middle adds a space between the two names. Without it you would get "AbebeGirma" — one squashed word. Concatenation is useful for building custom messages, like a receipt from a shop in Piassa that prints a customer's full name.
So far your programs have only displayed fixed text. Real programs are interactive — they ask questions and respond to what the user types. Python's input() function does exactly this:
name = input("What is your name? ")
print("Selam, " + name + "!")
When Python reaches the input() line it:
1. Shows the prompt message: What is your name?
2. Waits for the user to type something and press Enter.
3. Stores whatever the user typed in the variable name.
If Sara types Sara, the program then prints: Selam, Sara!
The message inside input("...") is called the prompt — it tells the user what to type. Always end your prompt with a space or a colon-space so the user's typed text does not appear right next to the question.
Let us combine everything into a small, useful program — a personalised greeter that could work at the start of any Ethiopian app:
# Personalised greeter
name = input("Enter your name: ")
city = input("Enter your city: ")
print("Welcome, " + name + "!")
print("We are glad you joined us from " + city + ".")
print("Your TeleBirr account is ready.")
If the user types Almaz and Hawassa, the output is:
Welcome, Almaz!
We are glad you joined us from Hawassa.
Your TeleBirr account is ready.
By changing a few lines you could adapt this for a pharmacy in Jimma, a coffee export company, or a school registration form. That is the power of combining strings and input() — your program responds to real people.
Joining strings with + works, but it can get messy with many pieces. Python offers a cleaner tool called an f-string (formatted string). You put f before the opening quote and then place variable names directly inside {} braces:
name = "Sara"
city = "Dire Dawa"
print(f"Welcome, {name}! You are logged in from {city}.")
Output:
Welcome, Sara! You are logged in from Dire Dawa.
The f at the start tells Python: "look for {} placeholders and fill them with the variable values". f-strings are the modern, preferred way to build text in Python. They are easier to read than long + chains — especially when a message has three or more pieces.
Scenario
Dawit is writing a program that asks a user for their phone number and then prints it. He writes: phone = input("Enter your Ethio Telecom number: ") print("Your number is: " + phone) When he runs it and types 0912345678, what does Python print?
Check your understanding
1/7 · 80 XPWhich of the following is a valid Python string?