Ram

Lesson 9 of 19

Strings & Formatting

Clean, combine and format text values.

Introduction

Strings are sequences of characters. Use indexing and slicing to read portions of text, and methods such as lower, upper and strip to clean it.

F-strings put expressions inside braces so messages can include values without awkward concatenation.

Key insight

Clean, combine and format text values.

Example

name = "Asha"
city = "Kathmandu"
print(f"{name} lives in {city}.")

This example shows the core strings & formatting idea in a small, runnable program.

Real-world example

Strings & Formatting appears in everyday application code, scripts and APIs.

Test yourself

2-question check

1

What is the main idea in Strings & Formatting?

2

Where can strings & formatting be useful?

Ready to check your understanding?

Answer every question, then submit your quiz.

Try it yourself

Python compiler

Runs in your browser. Nothing is sent to a server.

Output appears here

First run downloads the Python runtime, so it may take a moment.

Practice challenge

Format a sentence that includes a product name and price.

Previous
Next