1.2. Printing#
In order to get the computer to display information to the screen, we use the
print() function.
Try running the code below!
print("I love Python")
Take note of the following:
printmust be in lower case. If you try usingPrint, it won’t work! This is because the computer is fussy! It can only understand very specific instructions.'I love Python'is just a piece of text. This is the information we want to display.We use ‘ ‘ or “ “ to indicate text. (We actually refer to text as a string; more on this later.)
We tell the computer what to display by placing the contents in circular brackets ().
This is the structure of the print() function:
print(information_you_want_to_display)
1.2.1. Exercises#
Which of the following code snippets are valid? Select all that apply.
print["I can code!"]
print('Computers are fun!')
print('Programming is awesome!)
print(Developing software is cool!)
print('Programming rules!')
print('Don't code while sleepy!')
Write a Python program which displays the text Hello World!
The output of your program should look like this:
Hello World!
Write a program which displays the following message.
It should look like this:
To become a great Python programmer you need to
practice, practice, PRACTICE!!!
Hint
Use two print() statements.
Note
Did you know? You can solve this challenge in one line! See what happens when you try print('Hello\nWorld!').