ABK TechnologiesPractical technology for real-world impact

String Formatting in Python: A Simple Guide for Beginners

December 1, 2025 · 1 min read


String Formatting in Python: A Simple Guide for Beginners

When learning Python, one of the first things you’ll do is print information to the screen. But as your programs grow, you’ll need clean and readable ways to display text, especially when combining sentences with variables. This is where string formatting becomes important.

The image above introduces two powerful ways to format strings in Python: the .format() method and f-strings.

Using the .format() Method

The .format() method has been around in Python for a long time. It uses curly braces {} as placeholders, and then replaces them with values you provide.

Example:

name = “Joy”
age = 22

print(“My name is {} and I am {} years old”.format(name, age))

Output:
My name is Joy and I am 22 years old

Here’s what’s happening:

{} acts as placeholders

format(name, age) inserts the values in order

It helps keep your code organized

However, .format() can become hard to read when you have many variables or longer text.

Introducing f-Strings (Python 3.6 and above)

To make things easier, Python introduced f-strings, which are now the most popular way to format text.

Example:

print(f”My name is {name} and I am {age} years old”)

Why developers love f-strings:

They are more readable

You write variables directly inside the curly braces

They run faster than .format()

They look clean and modern

If you’re using Python 3.6 or newer (which most people are), f-strings should be your go-to choice.

Conclusion

String formatting might look small, but it has a big effect on how clean and professional your Python code looks.

If you’re just starting your Python journey in Ghana, Africa, or anywhere in the world, mastering formatting early will make your coding experience smoother.

Whether you’re building a school project, a data analysis script, or even a web application, understanding .format() and f-strings will definitely come in handy.


Join the conversation

Leave a comment

Your email address will not be published. Comments are reviewed before they appear.