Skip to content

Learning Objectives

  • Understand the importance of printing
  • Understand how to use the print() function (without variables)
  • Understand how to print multi-line strings in Python

Printing

In order to print some text in Python, we can use the print() function and wrap any text in inverted commas:

python
print("Hello World")

OR

python
print('Hello World')

Printing Multi-Line Strings

In order to print in mulitiple lines, we can use wrap the text in triple inverted commas ('''):

python
print('''
Hello Python
This is my first program!
''')

OR

python
print("""
Hello Python
This is my first program!
""")

Inverted Commas Conflict

If we are using the ('), but also use it as a astrosphe (e.g. 's)

python
print('Hello, I'm using Python')

It will result in: SyntaxError: unterminated string literal (detected at line 1)

We can either switch to double inverted commas ("):

python
print("Hello, I'm using' Python")

OR

We can use a ('\') before the non-terminal inverted comma:

python
print('Hello, I\'m using Python')

Practices

  • Use the print() function to print out your name
  • Use a multi-line string with the print() function and write a paragraph to introduce yourself