How do you format strings in Python?

Python data types and strings · Freshers

Model answer

Use f-strings: f"Hello {name}, you are {age}". They support expressions and formatting like {price:.2f}. Older ways are str.format() and the % operator, which still appear in older code.

Learn this topic

Variables, Numbers, Text and input() in Python in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions