Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

How to Print Strings and Integers Together in Python

Print text and integers in Python with separate print() arguments or f-strings, and learn when to use format(), str(), and int().
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use multiple arguments to print() for a simple space-separated result, or an f-string to combine text and a number into one formatted string:

age = 42
print("Age:", age)
print(f"Age: {age}")

The first call prints Age: 42 because print() separates its arguments with a space by default. The f-string produces the same visible output while placing the value directly into the label.

Choose the right way to combine text and a number

Approach Best for Example
Multiple print() arguments A quick display with a space between values print("Score:", score)
F-string A sentence, label, or output that needs numeric formatting print(f"Score: {score}")
str.format() A reusable template with values supplied separately, or code already written in this style print("Score: {}".format(score))
Explicit conversion with str() String concatenation when you specifically need one string joined with another print("Score: " + str(score))

For modern Python, an f-string is usually the clearest choice when the text and value form one message. Separate print() arguments are simpler when a default space is exactly what you want. Python’s tutorial presents f-strings and str.format() as ways to control output beyond space-separated values: Python 3.14 tutorial: Input and Output.

Print a string and an integer with multiple arguments

Pass the text and integer as separate arguments. Python does not need to convert the integer to a string first:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
name = "Mina"
score = 95

print("Name:", name, "Score:", score)

Output:

Name: Mina Score: 95

print() uses a space as its default separator. To choose another delimiter, set sep:

print("Name", name, "Score", score, sep=" | ")

This prints Name | Mina | Score | 95. Use a custom separator only when the output calls for it; for a sentence with punctuation or labels, an f-string is often easier to read.

Use an f-string for a sentence or label

Put an f before the opening quote, then place a variable inside braces. Python inserts its value into the string:

name = "Mina"
score = 95

print(f"{name} scored {score} points.")

Output:

Mina scored 95 points.

F-strings also let you control how a number looks. Put a format specifier after a colon inside the braces:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
count = 7
price = 12.5

print(f"Items: {count}")
print(f"Price: ${price:.2f}")
print(f"Count: {count:04d}")

The .2f specifier displays the price with two digits after the decimal point; 04d displays the integer with a total width of four characters, padded with zeroes. Choose precision and padding to suit the output rather than treating either format as a universal default. Python’s tutorial documents format specifications, including decimal precision and field width: Python 3.14 tutorial: Input and Output.

Use str.format() when a template suits your code

str.format() is another valid way to insert values. It can be useful when a template and its values are kept separate, or when working in code that already uses this style:

name = "Mina"
score = 95

message = "{} scored {} points.".format(name, score)
print(message)

The braces mark the places where format() inserts the arguments in order. For a short inline message in modern Python, an f-string is typically more concise.

Why string concatenation with an integer fails

A string is text, while an integer is a numeric value. The expression "Score: " + 95 raises a TypeError because Python cannot concatenate a string and an integer directly. If you specifically need concatenation, convert the integer explicitly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
score = 95
print("Score: " + str(score))

For most display code, prefer an f-string or separate print() arguments; they make the intended output easier to see. Python documents str() as a way to produce a human-readable string representation: Python 3.14 tutorial: Input and Output.

Handle numbers read with input()

input() returns text, even when the user types digits. Convert that text with int() when you need integer arithmetic; use an f-string to display the resulting value:

age_text = input("Enter your age: ")
age = int(age_text)
print(f"Next year, you will be {age + 1}.")

If the input might not be a whole number, int() can raise a ValueError. For this simple example, the user must enter text that represents a valid integer. The Python tutorial explains that input is read as text and must be converted when a number is needed: Python 3.14 tutorial: Input and Output.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Understand why printed strings look different from shell output

print() displays the contents of a string without surrounding quotation marks. By contrast, an interactive Python shell may show a string’s representation, which includes quotes so the text value is recognizable:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
>>> message = "hello"
>>> message
'hello'
>>> print(message)
hello

Use str(value) when you want a human-readable string. repr(value) is useful when you want a representation that makes quotes or escape characters visible. The official tutorial and introduction describe these display behaviors: Input and Output and An Informal Introduction to Python.

Distinguish an integer from digits stored as text

42 is an integer; "42" is a string containing two digit characters. Both can appear on screen as 42, but only the integer can be used directly in arithmetic:

number = 42
text = "42"

print(number + 1)  # 43
print(text + "1")  # 421

If digit text came from input() and you intend to do arithmetic, convert it to an integer first. Python’s introduction explains that digits enclosed in quotes are strings: An Informal Introduction to Python.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.