Displaying the result of your code is one of the first steps in learning Python. The print() function helps you show variable values in your terminal or console, making it easier to test and debug your code.


✨ Printing a Single Variable

To display the value of a variable, simply use the print() function:

greeting = "Welcome to GoNimbus!"
print(greeting)

🖥 Output:

Welcome to GoNimbus!

🔹 Displaying Multiple Variables (Using Commas)

Python lets you display multiple variables in one go by separating them with commas. It automatically adds spaces between them.

city = "Hyderabad"
temperature = 32
print("Current temperature in", city, "is", temperature, "degrees.")

🖥 Output:

Current temperature in Hyderabad is 32 degrees.

➕ Concatenating Strings with the + Operator

Use the + operator to join strings. Make sure to manage spacing manually:

first_name = "Ada"
last_name = "Lovelace"
print(first_name + " " + last_name)

🖥 Output:

Ada Lovelace

⚠️ If you forget the space (" "), the names will be joined without space.


➕ Adding Numbers

When used with numbers, the + operator performs addition:

length = 12
width = 8
print("Total area:", length + width)

🖥 Output:

Total area: 20

❌ Mixing Strings and Numbers with +

Attempting to join a string and a number using + will result in an error:

age = 30
# print("Age: " + age)  ❌ This will throw an error

✅ Instead, use commas:

print("Age:", age)

🖥 Output:

Age: 30

🧠 Smart Formatting with f-Strings

For a cleaner and more dynamic output, use f-strings. It allows you to directly insert variable values inside strings.

user = "Charlie"
points = 120
print(f"{user} has earned {points} points today.")

🖥 Output:

Charlie has earned 120 points today.

💡 Try It Yourself on GoNimbus

Test the output examples using our GoNimbus Python Playground:

item = "Laptop"
price = 49999
print(f"The {item} costs ₹{price}.")

👉 Launch Python Editor on GoNimbus


✅ Quick Summary

TaskMethod
Print one variableprint(variable)
Print multiple valuesprint(var1, var2)
Concatenate stringsprint(var1 + var2)
Add numbersprint(num1 + num2)
Embed variables in stringsprint(f"text {variable}")

Scroll to Top