Sitemap

Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Dealing With Input and Output in Python

A short guide to using the input and print functions in Python

4 min readJun 15, 2021

--

Getting Started
Understanding input and output is the first skill required to obtain mastery of the Python programming language. To get started let us first take a look at the image below.

Press enter or click to view image in full size
Image

For simplicity sake, we are going to treat the inner workings of the program as a black box as shown in the above image. This allows us to only focus on information coming into the program (input) and information leaving the program (output).

For now, what the program does with this information will be considered as part of the “black box” and will be ignored. Conceptualizing input and output in this way allows us to recognize that the computer program itself is a separate entity that we as users are interacting with through the medium of input and output.

Input

There are multiple ways to deal with input in Python programming. For now, we are going to talk about one of the most common ways to read in input: the input function.

Python has a built in function that receives text input from the user. Take a look at the code snippet below. Note that the line that starts with a # is a comment. Adding comments to your code is an incredibly helpful way to document your code. Python will ignore all lines that start with a #, so adding in comments will not cause any errors in your code.

# The following line of code receives text input from the user
input()

Notice that when you run this line of code the cursor on your screen blinks? Try typing in some text and hitting the enter button. Did you get what you expected?

Your program should have finished as soon as you entered in some text. That seems a little strange right? What happened to the information that you entered? Let us go back to our image describing input and output.

Press enter or click to view image in full size
Image

Our diagram shows that input refers to information coming into the program! Input doesn’t return this information back out to us as…

--

--

Python in Plain English
Python in Plain English

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Banana Chip Tech
Banana Chip Tech

Written by Banana Chip Tech

Banana Chip Tech is focused on optimizing healthcare through computation! We build apps, create websites, and develop tech courses for healthcare professionals!

No responses yet