About this question
How can you print a formatted string in Python 3?
This question explores the different ways to format and print strings in Python 3 using techniques like f-strings, format(), and the % operator for clean and readable output.
How can you print a formatted string in Python 3?
This question explores the different ways to format and print strings in Python 3 using techniques like f-strings, format(), and the % operator for clean and readable output.
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Python Expert
Answered on Jun 25, 2025
In Python 3, printing a formatted string is super easy and flexible thanks to multiple formatting methods. Whether you're displaying variables, numbers, or text with specific alignment or precision, Python gives you several options.
1. Using f-strings (Recommended – Python 3.6+)
name = "Alice"
age = 30
print(f"My name is {name} and I am {age} years old.")Clean and readable
Allows inline expressions and even formatting like:
price = 12.3456
print(f"Price: {price:.2f}") # Output: Price: 12.352. Using .format() method
print("My name is {} and I am {} years old.".format(name, age)) print("Name: {n}, Age: {a}".format(n="Bob", a=25))3. Using % operator (Old-school)
print("Name: %s, Age: %d" % (name, age))So, the best way to print formatted strings in Python 3 is by using f-strings—they're concise, readable, and super powerful. But it's good to know .format() and % exist, especially when working with legacy code.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Python interview questions, answered
Guides, tips and career advice on Python from JanBask experts.
Python How to Become a Python Developer: A Step-by-Step Guide for Beginners
Discover how to become a Python Developer via a practical 7-step guide build projects, maintain clean code, practice daily, and…
Python PCEP Certification Guide: Entry-Level Python Programmer Certification
Explore this PCEP certification guide for insights on cost, exam format, passing score, application, training, and study tips.…
Python Top 50+ Python Projects ideas for Beginners to Advanced
Discover innovative Python project ideas, explore advanced Python projects, and find good Python projects for beginners and…
Python How To Comment Out Multiple Lines In Python Like A Pro
Commenting out code is a common practice among programmers. It allows you to temporarily disable parts of your code without…