Python 1a - Printing
Printing in Python
To output a message onto the screen, use the print command.
Then place your message within brackets and speech marks. For example:
print("Welcome to Python!")
When you run the program, the text will print to the Python console:
Welcome to Python!
Printing Task 1 (Full Name & To Your Left)
On the first line, print your first name and surname.
​
On the next line, write another print statement to print the name of the person (or thing) to your left.
Example solution:
Elsie Parker
pencil case
Printing over Several Lines
One way of writing across multiple lines is to write several print commands like this:
print("Welcome to....")
print("Computer Science")
print("Newbies!!!")
=
Welcome to ....
Computer Science
Newbies!!!
However, when we program, we always want to make our code the most efficient it can be by using as few lines as possible.
​
Therefore you can write \n within a printed statement to move it to the next line.
​
Make sure you use \ and not / otherwise it will print the slash and not make a new line!
print("Welcome to....\nComputer Science\nNewbies!!!")
=
Welcome to ....
Computer Science
Newbies!!!
Both pieces of code display the same thing, but the second one is more efficient because it only uses one line.
Printing Task 2 (Name, Colour, Movie)
Use \n to write your name, favourite colour and favourite movie in only one line of code.
Example solution:
Matthew
yellow
Interstellar