Print Multiple Lines - Lakelands Computing

Title
Go to content
The Print () Function
Escape Characters and Multiple lines
We have already seen that the print () function can be used to output text and variables to screen. There are some tricks and techniques that can make it much more useful. You might also want to look at this page on string formatting

In a python string the \ is a Special character or to use its proper name, an Escape character. It can be used to issue commands:

  • \n will give you a new line
  • \r will give you a new line using a carriage (like you would in Word). This may look the same as \n but the way it is stored in a text file is different which can be useful
  • \t will tab in the text (great for menus)
  • \\ will write the \ as part of the string (try it below it will make sense - just add a \\ to one of the print statements)

Multiple lines
Sometimes you may wat to have multiple lines of text without having to use the \n esacpe. This can be achieved using triple quotes: """  text """ (example in trinket)
All Text copyright Lakelands Academy & Mr T Purslow 2020.
All images copyright free / creative commons unless otherwise stated.
You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
Back to content