SwadhyAI Notes

All Python notes

Python Output Variables 📤

The print() Function

The Python print() function is often used to output variables.

✨ Basic Output

python
x = "Python is awesome"
print(x)

🔗 Multiple Arguments

In the print() function, you output multiple variables, separated by a comma:

python
x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
# Output: Python is awesome

➕ Using + Operator

You can also use the + operator to output multiple variables:

python
x = "Python "
y = "is "
z = "awesome"
print(x + y + z)
# Output: Python is awesome

⚠️ Watch Out!

If you try to combine a string and a number with the + operator, Python will give you an error:

python
x = 5
y = "John"
print(x + y) # TypeError!

✨ Pro Tip

The best way to output multiple variables in the print() function is to separate them with commas, which automatically adds a space and supports different data types!

python
x = 5
y = "John"
print(x, y)
# Output: 5 John