Skip to content

Input and Output

When you write a program, not everything should stay within the code. Sometimes you need to show information to the user (output), and other times ask for data (input). In Python, this is mainly done with two very simple functions:

  • print() to display messages or results.

  • input() to receive data from the user.

With these two functions you can start building interactive programs.

The print() function in Python is used to display information in the console. It allows you to print text, numbers, variables, and more, using simple syntax.

print.py
print('Welcome to PyDocs') # Response in console print('Welcome to PyDocs')

The input() function in Python asks the user to enter a value. Then, it reads what the user enters and returns it as a string.

print.py
name = input('What is your name? ')
print('Hello, ' + name + '!')