PyPyPath

Module 2: Python Basic Syntax and Data Types

Input and Output

Output means showing something on the screen. Input means asking the user to type something. These two ideas are how your programs talk to people.

About 10 minutes

Output with print()

The print() function displays text (or numbers) in the console. Whatever you put inside the parentheses is shown as output.

Example code
print("Hello, world!")
print(42)
print("I love Python", "for data science")
How print() works

print(...)

Your code

Python

Runs it

Console

Text appears

Input with input()

input() waits for the user to type something and press Enter. It always gives you back a string (text), even if the user types numbers.

Example code
name = input("What is your name? ")
print("Nice to meet you,", name)

In the browser IDE, input() may show a small popup box. On your own computer it works in the terminal the same way.

Practice

Print your favorite food. Then (optional) use input() to ask your name and greet yourself.

Key takeaways

  • print() shows output on the screen.
  • input() reads text from the user (always as a string).
  • You can print words, numbers, and several items separated by commas.

Quick check: Input and Output

Question 1 of 2

Which function displays text on the screen?