flowchart LR
prompt["input prompt<br/>What is your name?"] --> user["user types<br/>Ada"]
user --> text["Python stores text<br/>'Ada'"]
text --> build["build message<br/>f'Hello, {name}!'"]
build --> output["print output<br/>Hello, Ada!"]
Strings, Input, and Output
Questions
- What problem does Strings, Input, and Output help us solve in a small Python program?
- What should we predict before running the example?
- What value, output, or error should we inspect after changing one line?
Objectives
- Run a complete example for strings, input, and output in Colab.
- Explain the example line by line using plain language.
- Change one part of the code and predict the result before running it.
- Recognize one common mistake and use the error message as evidence.
Hands-on episode: Strings, Input, and Output
A string is a text value. print displays values, f-strings combine stored values with text, and input always returns text even when the person typed digits.
We will learn this by running code, not by memorizing a definition first. Open the Colab notebook from the button above, find this section, and run each cell in order. Keep a small note beside the notebook with three columns: prediction, actual result, and what changed.
Example 1.1
Predict the exact message, including spaces and punctuation.
Run the cell once without editing it. If the result is different from your prediction, leave the prediction visible and write one sentence about the difference. That sentence is more useful than a perfect first guess.
Explain Example 1.1
- The first line stores the text
Mayaunder the namename. - The second line stores the integer
8under the namescore. - The f-string starts with
f, so Python replaces{name}and{score}with their current values. print(message)displays the final string, not the wordmessage.
Now explain the example out loud or in a Markdown cell. Use short sentences: “this line creates…”, “this name stores…”, “this output appears because…”. If you cannot explain a line yet, run only the lines above it and inspect the values that exist at that moment.
Challenge 1.1
Remove the f before the string and run again. The braces will print literally. This small experiment shows that the f is not decoration; it changes how Python interprets the string.
Show a safe way to approach the challenge
- Copy Example 1.1 into a new Colab cell.
- Change exactly one value, name, condition, or line.
- Write the expected output before running the cell.
- Run the cell and compare the actual result with your prediction.
- If the result surprises you, undo the change and try a smaller one.
Suggested first move: Remove the f before the string and run again.
Debugging checkpoint 1.1
The classic beginner bug is adding input directly to a number. input() returns a string, so age = input(...) gives you text. If you need arithmetic, convert intentionally with int(age) or float(age) and be ready to handle invalid input later.
Do not debug by rewriting the whole example. Read the error type or surprising output, inspect the closest value with print(...) or type(...), then change one thing. This is the same routine you will use in larger projects.
Apply it
In Colab, ask for a learner’s name and favorite topic. Print a two-sentence welcome message using an f-string. Then ask for a number, convert it, add one, and print the result.
Finish by adding a Markdown cell that answers: What did this example teach me that I can reuse in a project?
Key points
- Learn the concept by running a complete, small example first.
- Predict before execution so your thinking becomes visible.
- Change one thing at a time so cause and effect stay clear.
- Treat errors as clues about the exact line or value Python could not handle.
The problem this lesson solves
Most beginner programs need to talk with people. They display instructions, show results, and sometimes ask the user to type information. Python uses strings for text, print() for output, and input() for simple input.
A string is not just “words”. It can contain letters, digits, spaces, punctuation, emojis, and line breaks. This matters because a program often needs to build messages such as:
In this lesson you will learn how text values work, how to combine them safely, and why user input must often be converted before doing math.
How input becomes output
A simple interactive program is a conversation: prompt, receive text, process, then print a reply.
The important beginner detail is that input() always gives you text, even when the user typed digits.
1. Strings are text values
A string is a value that represents text. In Python, the most common way to create a string is to put quotation marks around the text.
The quotation marks tell Python: “treat this as text”. The quotes are not part of the text displayed to the user; they are the boundary markers in your code.
Example 1
Before running this code, predict the four printed lines.
Step-by-step explanation
word = "Python"- Python creates a string value containing the six characters
P,y,t,h,o, andn. - The name
wordnow refers to that string.
- Python creates a string value containing the six characters
print(word)- Python looks up
wordand displays the whole string:Python.
- Python looks up
print(word[0])- Python strings are ordered. The first character is at index
0, not index1. word[0]is"P".
- Python strings are ordered. The first character is at index
print(word[-1])- Negative indexes count from the end.
word[-1]is"n", the last character.
print(f"I am learning {word}.")- The
fbefore the opening quote makes an f-string. - Anything inside
{...}is evaluated by Python. {word}is replaced by the value ofword, so the output isI am learning Python.
- The
Why indexes start at 0
Think of indexes as distance from the beginning. The first character is zero steps away from the beginning, so its index is 0.
Joining strings
You can join strings with +:
The middle string, " ", is a space. Without it, the result would be "AdaLovelace".
For longer messages, prefer f-strings because they are easier to read:
Common mistakes
Check your understanding
2. Input and output
print() sends information out of a program. input() brings information in from the user.
When Python runs the first line, it pauses and waits. Whatever the user types is returned as a string and assigned to name.
Example 2
Try this in Google Colab or a local notebook. In Colab, use the play button on the left side of the code cell.
Step-by-step explanation
input("How old are you? ")- The prompt text is displayed.
- The user types something, such as
12. - Python returns the text value
"12".
age_text = input(...)- The name
age_textstores that text.
- The name
age = int(age_text)int(...)tries to convert the text into an integer.- If
age_textis"12", the result is the number12.
next_year = age + 1- Now the value is numeric, so arithmetic works.
print(f"Next year you will be {next_year}.")- The result is placed inside the message and printed.
Why conversion matters
input() always returns a string. This surprises many beginners.
If the user types 5, the output is 55, not 10, because Python is joining strings. Convert first when you need arithmetic:
Common mistakes
Try it
In the notebook, create one code cell and build a tiny greeting program:
Then change one thing at a time:
- Add a third input for a favorite food.
- Print the final message on two lines.
- Ask for a number and convert it with
int().
Check your understanding
Key points
- Strings are text values surrounded by quotes in your code.
- String indexes start at
0; negative indexes count from the end. - F-strings let you place Python values inside messages.
print()displays output.input()returns text, so convert withint()orfloat()before arithmetic.
References
- Python Tutorial: strings: https://docs.python.org/3/tutorial/introduction.html#strings
- Python built-in functions:
print,input, andint: https://docs.python.org/3/library/functions.html - Google Colab: https://colab.new