Python, from Zero, for AILesson 7 of 89

Module 1 · Getting Python running, and your first working code

Building the output a person will read

In this lesson

  • 7 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 7 of 10 in this chapter

This chapter’s goalInstall Python on a laptop, a phone or a free browser machine, run the same code both interactively and from a saved file, and predict what a short program prints by naming the type of every value in it and the branch a condition takes.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:49Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 9Free · no account needed
Lesson steps

f-strings, and why the plus sign fails

You want to print a sentence with a value in it. The obvious attempt:

Python
name = "Asha"
owed = 1250
print("Hello " + name + ", you owe " + owed)
Text
TypeError: can only concatenate str (not "int") to str

+ between two strings joins them; between a string and an int it has no defined meaning, so Python refuses rather than guessing. You could wrap it in str(owed), and people did for years. The modern way is an f-string: put an f before the opening quote and put expressions in braces.

Python
print(f"Hello {name}, you owe {owed}")

Anything can go inside the braces: a variable, arithmetic, a method call, an index:

Python
print(f"{name.upper()} owes {owed * 1.18:.2f} after tax")

The part after the colon is a format specification, and it is where most of the value is.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘Building the output a person will read’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/formatting-output (Accessed: 21 November 2026).