0% found this document useful (0 votes)
6 views2 pages

Python - Output Variables

Uploaded by

captainricardus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Python - Output Variables

Uploaded by

captainricardus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python - Output Variables

❮ PreviousNext ❯

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

ExampleGet your own Python Server


x = "Python is awesome"
print(x)
Try it Yourself »

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

Example
x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
Try it Yourself »

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

Example
x = "Python "
y = "is "
z = "awesome"
print(x + y + z)
Try it Yourself »
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)
Try it Yourself »

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)
Try it Yourself »

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)

You might also like