Skip to content

Print Statements

The print() function useful in Python. The value or expression inside of the parenthesis in the print() function "prints" out to the REPL when the print() function is called.

An example using the print() function is below:

>>> name = "Gabby"
>>> print("Your name is: ")
Your name is
>>> print(name)

Remember that strings must be enclosed by quotation marks. The following command produces an error.

>>> print(Gabby)

NameError: name 'Gabby' is not defined

This error is corrected by surrounding the string Gabby with quotation marks.

>>> print("Gabby")

Expressions passed to the print() function are evaluated before they are printed out. For instance, the sum of two numbers can be shown with the print() function.


If you want to see the text 1+2, you need to define "1+2" as a string and print out the string "1+2" instead.


Strings can be concatenated (combined) inside of a print() statement.

>>> name = Gabby
>>> print('Your name is: ' + name)
Your name is Gabby

The print() function also prints out individual expressions one after another with a space in between when the expressions are placed inside the print() function and separated by a comma.

>>> print("Name:","Gabby","Age", 3+5)
Name: Gabby Age 8