Output¶
Definition¶
Output in Python is carried out using the print
statement. print('text here')
will output text here
to the screen.
Note
Don’t use a space with the print statment. It should be written as print()
not print ()
.
Syntax¶
print(string)
Examples¶
Example 3 - Output a variable and string¶
name = 'Laura'
print('Hello ' + name)
Hello Laura
Example 4 - Output using a new line character¶
print('This text is on the first line \n and this text is on the second line')
This text is on the first line
and this text is on the second line
Note
The second line starts with a space character. To have no additional spaces you would use print('This text is on the first line\nand this text is on the second line')
Key points¶
Warning
The print statement should always be given a string to print. If you get an error on this statement make sure that you’re not trying to print a different data type, such as an integer - this is especially important if you are concatenating values together.
Hint
You can use print()
to simply print a blank line.
Note
\n
is a new line character. It is treated as a new line. It is a type of escape character.
Note
A sequence in programming is instructions which are run one after another in order. It is the most basic programming construct. Example 3 shows a very simple sequence with two instructions.