Text output

we can output to the terminal with print function. In this article we’ll show you how to
output text to the screen with Python.

Related Courses: Complete Python Bootcamp: Go from zero to hero in Python


To output text to the screen you will need one line of code:

print("Hello World")

If you run the program:

Hello World

To write multiple lines, add the ‘\n’ character:

print("Hello World\nThis is a message")

Results in:

Hello World
This is a message
Note: the characters \n create a new line


### Print variables

To print variables:
x = 3

This will show:

To print multiple variables on one line:

x = 2
y = 3
print("x = {}, y = {}".format(x,y))

Will give you:

x = 2, y = 3
Previous Post Next Post

Cookie policy | Privacy policy | ©