In this tutorial, I will explain how to print strings and integers together in Python. As a developer in the USA, I often need to combine different data types like strings and integers in my Python programs for various applications. Printing them together can be tricky if you’re not familiar with the proper techniques. Let’s get in and explore several methods to solve this common programming task.
Print Strings and Integers Together in Python
Python provides several ways to print strings and integers together in Python. Let us see some important methods.
Read Convert Int to Bytes in Python
1. Concatenate Strings and Integers
One way to print strings and integers together is by concatenating them into a single string before printing. However, you can’t directly concatenate a string with an integer using the + operator in Python. You’ll encounter a TypeError. For example:
name = "John"
age = 25
print("My name is " + name + " and I am " + age + " years old.")This will raise a TypeError: can only concatenate str (not "int") to str.
To fix this, you need to convert the integer to a string using the str() function:
name = "John"
age = 25
print("My name is " + name + " and I am " + str(age) + " years old.")Output:
My name is John and I am 25 years old.I have executed the above example code and added the screenshot below.

By converting the integer age to a string using str(age), you can now concatenate it with other strings in the print() function.
Read Convert DateTime to UNIX Timestamp in Python
2. Use f-Strings (Python 3.6+)
Python 3.6 introduced f-strings, which provide a more concise and readable way to include variables and expressions inside string literals. With f-strings, you can directly embed variables and expressions within curly braces {} inside the string. Python will automatically convert them to strings and include them in the output.
Here’s an example:
name = "Alice"
age = 30
print(f"My name is {name} and I am {age} years old.")Output:
My name is Alice and I am 30 years old.I have executed the above example code and added the screenshot below.

The f prefix before the string indicates that it’s an f-string. The variables name and age are placed inside curly braces {} , and Python will replace them with their respective values during runtime.
Read How to Find the Largest and Smallest Numbers in Python?
3. Use the format() Method
Another approach is to use the format() method, which allows you to insert values into a string template. You can define placeholders using curly braces {} within the string and then provide the values as arguments to the format() method.
Here’s an example:
name = "Michael"
age = 35
print("My name is {} and I am {} years old.".format(name, age))Output:
My name is Michael and I am 35 years old.I have executed the above example code and added the screenshot below.

The placeholders {} act as placeholders for the values that will be inserted. The format() method takes the values as arguments in the order they should be inserted into the placeholders.
You can also use indexed placeholders to specify the order explicitly:
name = "Emily"
age = 28
profession = "software engineer"
print("My name is {0}, I am {1} years old, and I work as a {2}.".format(name, age, profession))Output:
My name is Emily, I am 28 years old, and I work as a software engineer.The numbers inside the placeholders {0}, {1}, and {2} indicate the index of the arguments passed to the format() method.
Read How to Check if a Python String Contains a Substring?
4. Use the % Operator
Python also supports the % operator for string formatting, similar to the printf() style in C. With this method, you use % placeholders within the string and provide the values as a tuple after the % operator.
Here’s an example:
name = "David"
age = 42
print("My name is %s and I am %d years old." % (name, age))Output:
My name is David and I am 42 years old.The %s placeholder is used for strings, and %d is used for integers. The values are provided as a tuple (name, age) after the % operator.
Read How to Reverse a String in Python?
Conclusion
In this tutorial, we explored different ways to print strings and integers together in Python. I covered methods like concatenation, f-strings, the format() method, and the % operator which makes it easy to understand the concept.
You may also like to read:
- Find the First Number in a String in Python
- How to Compare Strings in Python?
- How to Create a String of N Characters in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.