0
0
Pythonprogramming~15 mins

String formatting using f-strings in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
String formatting using f-strings
📖 Scenario: You are creating a simple program to display information about a book in a friendly way. You want to show the book's title, author, and year of publication in a sentence.
🎯 Goal: Build a program that uses f-strings to format and display a sentence with the book's details.
📋 What You'll Learn
Create variables for the book's title, author, and year.
Create a variable for a short message prefix.
Use an f-string to combine the variables into a full sentence.
Print the formatted sentence.
💡 Why This Matters
🌍 Real World
Formatting strings nicely is useful for showing information clearly in apps, reports, or messages.
💼 Career
Many programming jobs require creating readable output for users, and f-strings make this easy and clean.
Progress0 / 4 steps
1
Create variables for book details
Create three variables: title with the value "The Great Gatsby", author with the value "F. Scott Fitzgerald", and year with the value 1925.
Python
Need a hint?

Use simple assignment statements to create the variables with the exact names and values.

2
Create a message prefix variable
Create a variable called message and set it to the string "Book Info:".
Python
Need a hint?

Just assign the string to the variable message.

3
Create a formatted string using f-string
Create a variable called formatted that uses an f-string to combine message, title, author, and year into this exact sentence: Book Info: "The Great Gatsby" by F. Scott Fitzgerald, published in 1925.
Python
Need a hint?

Use an f-string with curly braces to insert the variables inside the string.

4
Print the formatted string
Write a print statement to display the formatted string.
Python
Need a hint?

Use print(formatted) to show the final sentence.