The Python print() function is used to print the output. The print function accepts any number of parameters and inside the tinde brackets we can specify a string, a variable, or both. Printing takes place on one line of text.

Sintax print Python

print(value (s), sep = ”, end = ‘\ n’, file = file, flush = flush)

Where:

  • value is the value or values ​​to be printed. If nothing is indicated, it prints an empty line;
  • sep = ‘separator’: (optional) Separate words, phrases, or variables to be printed. The default separator is whitespace;
  • end = ‘end’: (optional) The default is ‘\ n’. Indicate what to print at the end;
  • file: (optional) The default is sys.stdout. Indicates an object with a writing method.
  • flush: (optional). The default is False. Indicates whether the output is unloaded (True) or buffered (False).

Print Python – examples

Let’s take some examples to better understand how it work.

Print a string:

>>> side = 5

>>> print(‘side’) #will print the word side

side

Print a variabile:

>>> print(side) #will print the word side

5

>>> print(‘The side value is: ‘, side)

The side value is: 5

Alternatively you can use:

>>> print(f’The side value is: {side}’)

Print Function and separator in Python

In Python we can use separators between words or variables to be printed. The default separator is whitespace.

Let’s take some examples to better understand the concepts:

>>> print(‘coding’,’creativo’)

coding creativo

>>> print(‘coding’,’creativo’,sep=’-‘)

coding-creativo

Print Function and end

The end keyword is used to specify the content to be printed after print().

Let’s give some examples:

>>> print(‘coding’)
>>> print(‘creativo’)

coding

creativo

>>> print(‘coding’, end =’ ‘)
>>> print(‘creativo’)

coding creativo

This is one way to print in python without newline!

Let’s try the code in the online compiler:


side = 5
print('The side value is: ', side)

print(f'The side value is: {side}')

print('coding','creativo',sep='-')

print('coding')
print('creativo')

print('coding', end =' ')
print('creativo')

In this lesson we have dealt with the Python Print() function, in the next lessons we will deepen its use.

Useful links

Python tutorial

Python Compiler

Install Python

Variables

Casting in Python