Output in Python is carried out using the
print('text here') will output
text here to the screen.
Don’t use a space with the print statment. It should be written as
Example 1 - Output a string¶
Example 2 - Output a variable¶
name = 'Smith' print(name)
Example 3 - Output a variable and string¶
name = 'Laura' print('Hello ' + name)
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
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')
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.
You can use
print() to simply print a blank line.
\n is a new line character. It is treated as a new line. It is a type of escape character.
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.