bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python - Output Variables

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Python - Output Variables?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

x = "___ is awesome"
3Order

Put the learning moves in the order that makes the concept easiest to apply.

You can also use the + operator to output multiple variables:
In the print() function, you output multiple variables, separated by a comma:
The print() function is often used to output variables.

Output Variables

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

Example

x = "Python is awesome"

print(x)

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

Example

x = "Python"
y = "is"
z = "awesome"
print(x, y, z)

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

Example

x = "Python "
y = "is "
z = "awesome"
print(x
+ y + z)

Notice the space character after "Python " and "is " , without them the result would be "Pythonisawesome".

For numbers, the + character works as a mathematical operator:

Example

x = 5
y = 10
print(x + y)

In the print() function, when you try to combine a string and a number with the + operator, Python will give you an error:

Example

x = 5
y = "John"
print(x + y)

The best way to output multiple variables in the print() function is to separate them with commas, which even support different data types:

Example

x = 5
y = "John"
print(x, y)

Previous

Python Variables - Assign Multiple Values

Next

Python - Global Variables