top of page

Python - Print function


Printing in Python


Introduction

In this article, we will learn how to display information on the screen. We will start with printing texts composed of letters, numbers, and other symbols.


Print

Many Python instruction names are derived from English words, which is helpful when writing and reading code. For example, the instruction used for printing is called print. After the word print, within parentheses, we specify what should be displayed on the screen. The outputted text should be enclosed in quotation marks. For example:


print("Codeforia")
 

will display on the screen:


Codeforia
 

and


print("Programming is fun! :)")
 

will display:


Programming is fun! :)
 

New line character

The transition to the new line (commonly referred to as 'enter') is denoted as \n (a combination of two characters). For example:


print("Code\nfor\nia")
 

will display:


Code
for
ia
 

'end' parameter

A program may contain multiple instructions. We write each of them in a separate line. For example:


print("One")
print("Two")
print("Three")
 

will display:


One
Two
Three
 

Notice that by default, after executing a print instruction, there is a new line. We would achieve the same result by running the code:


print("One\nTwo\nThree")
 

We can specify what should be displayed after the print instruction is executed instead of the default end of line (\n). It is sufficient to set the value of the end parameter. Place the end parameter inside the parentheses after the text we want to print. For example:


print("One", end="$")
print("Two", end="?")
print("Three", end="*")
 

will print messages ending respectively with $, ? and *:


One$Two?Three*
 
 

Train with us!

example lesson on codeforia

Programming is a crucial aspect of learning to code. You can practice it by solving tasks (micro-projects) available on our educational platform Codeforia. Solutions are automatically checked, and shortly after submitting your code, you'll find out whether it's correct or needs modification. We also invite you to join our regular online classes, where you can further develop your skills under the guidance of an experienced trainer.

Check out our available courses.

留言


Kursy programowania dla dzieci i młodzieży.

bottom of page