Fundamentals 5 min read

5 Powerful Ways to Use Python’s print() Function

Discover five versatile techniques for Python’s print()—from simple string concatenation and comma separation to modern f‑strings, percent formatting, and the .format() method—complete with clear examples and guidance on when to use each approach for clean, readable output.

Code Mala Tang
Code Mala Tang
Code Mala Tang
5 Powerful Ways to Use Python’s print() Function

If you program in Python, you probably know the print() function as the simplest way to display output, but many developers are unaware of its multiple usage patterns.

Method 1: String Concatenation

This method joins strings using the + operator. Only strings can be concatenated, so non‑string values must be converted with str().

name = "Aliyan"
age = 23
print("My name is " + name + " and I am " + str(age) + " years old.")
# Output: My name is Aliyan and I am 23 years old.

Method 2: Using Commas

Separate items with commas instead of +. Python inserts spaces automatically and handles non‑string types without explicit conversion.

city = "Lahore"
population = 13000000
print("The city of", city, "has a population of", population, "people.")
# Output: The city of Lahore has a population of 13000000 people.

Method 3: f‑Strings

Introduced in Python 3.6, f‑strings (formatted string literals) allow direct variable insertion using {} inside the string, offering concise and readable code.

product = "Laptop"
price = 85000
print(f"The {product} costs {price} rupees.")
# Output: The Laptop costs 85000 rupees.

Method 4: Percent Formatting

Before f‑strings, the % operator was common. Placeholders like %s, %d, and %f indicate string, integer, and float values.

language = "Python"
version = 3
print("I am learning %s version %d." % (language, version))
# Output: I am learning Python version 3.

Method 5: .format() Method

The .format() method inserts variables into placeholders marked by curly braces, offering flexibility over percent formatting.

subject = "Mathematics"
score = 95
print("I scored {} marks in {}.".format(score, subject))
# Output: I scored 95 marks in Mathematics.

Final Thoughts: Best Way to Print in Python

Python provides several ways to use print(). Practice all five to understand their behavior, but for production code, prefer f‑strings for professional, readable output.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Code Examplesstring formattingprintf-strings
Code Mala Tang
Written by

Code Mala Tang

Read source code together, write articles together, and enjoy spicy hot pot together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.