Print

Printing to the console allows you to see the results of your program. To print to the console, use the print() function. Functions have a unique name, and to use them, simply write their name followed by a pair of parentheses. Often, functions need extra information called arguments in order to work, which are included inside the parentheses. Example of printing a string, which is a sequence of characters:
print("Hello World!")
# Hello World!
You can print almost anything, including numbers, variables, and more:
print(45)
# 45
  
greeting = "hello"
print(greeting)
# hello
Strings have certain special characters. The most important ones are:
  • \n - creates a new line
  • \t - creates a tab
Example of using \t to indent, and \n to create a new line:
print("\tHello\nWorld!")
#   Hello
# World!

Exercise 1 of 6

Which special character creates a tab?

Your answer

Exercise 2 of 6

Which special character creates a new line?

Your answer

Exercise 3 of 6

Fix the error in the line of code.
print("\tWelcome to my program"\n)

Your code

Exercise 4 of 6

Write a line of code to print the word "tab" with two indents before and after the word.

Your code

Exercise 5 of 6

Fix the error in the line of code.
print(hello world)

Your code

Exercise 6 of 6

Write a line of code to print your name.

Your code