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.
#1 Best Overall
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:
Rank #2
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:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallcount = 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:
Recommended Free Tools
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.
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:
Best Value
>>> 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.
Quick Recap
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.




