Loading lessons...
Output Variables
Printing variables is how you see what your program is doing.
Print a single variable
python
x = "Python is awesome"
print(x)
### Python is awesome
Print several variables
Use commas to print multiple values with spaces:
python
x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
### Python is awesome
Combine strings with +
For strings you can also use +:
python
print(x + y + z)
### Pythonisawesome
Notice there is no space this time!
Numbers and + or comma
With numbers, + means addition:
python
a = 5
b = 10
print(a + b)
### 15
But mixing a string and a number with + fails:
python
print(x + a)
### TypeError
The comma version always works:
python
print(x, a)
### Python 5
TL;DR
print(x)prints one variable.- Commas add spaces and mix any types.
+glues strings but adds numbers.- Never mix string and number with
+.