Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Reading Input and Writing Output in Python (Summary)

In this course, you learned about Python input and output and how your Python program can communicate with the user. You should now have a good foundation for obtaining data from a user with input() and displaying results to the console with print().

In this course, you learned how to:

  • Take user input from the keyboard with the built-in function input()
  • Display output to the console with the built-in function print()

Sample Code (.zip)

715 bytes

Course Slides (.pdf)

2.4 MB

00:00 You’ve arrived in the final lesson of this course, and in this lesson, you’re just going to go over the different functions that you used and learned about in this course. First, you learned about using the input() function to collect input from a user and optionally that you can pass in a string as a prompt that gets displayed before where Python is expecting you to put your input.

00:21 This can make it a little bit more sensical for your users as to what they’re supposed to type in for what your script needs to continue execution.

00:31 Next, you learned that the input() function always returns a string, so if you want to do a numerical computation with it, you need to convert it—for example, to an integer—by wrapping the input that you collect from the user in this explicit type conversion, and then you can do a numerical operation like the age calculation that you did in this course.

00:51 Then you learned how to display that output back to the user by using the print() function. Now, you might remember that if you use the Python interpreter, you get the output displayed automatically, but if you write Python in a script, you need to explicitly tell Python what it should display back to the user in the console. You can do this by passing arguments—one or many arguments—to the print() function. Additionally, you learned that you can also pass keyword arguments to the print() function, specifically the separator and the end keyword argument. And with these two, you can customize how Python displays the arguments that you pass to print() to the console.

01:30 So, the separator—whatever string you put in there—is going to be input in between the arguments that you pass to print(), and the end string that you pass in here is going to come at the very end of the string that the print() function builds and then returns to the user.

01:46 And this wraps up this course about reading input and writing output in Python. As possible next steps, I would suggest you to build a couple of small scripts using input() and print() to train using these two important functions in Python. You could, for example, build a little script that greets users, just like you saw in the image before, where you prompt the user to input their name and then display a little greeting for them.

02:09 And then you could also start building a small game where you collect some user input and then actually do something in your code logic and keep communicating back to the user what’s happening in the game with the print() function. I hope this was helpful for you, and I hope to see you around at Real Python. My name is Martin, and have a nice day!

Avatar image for aniketbarphe

aniketbarphe on Nov. 7, 2021

Thank You!

Avatar image for doxsee

doxsee on Nov. 21, 2021

Thanks for highlighting ‘sep’ and ‘end’.

Avatar image for MAStough

MAStough on Jan. 7, 2022

Agreed with doxsee…I didn’t know you could specify a ‘sep’ and ‘end’ value. I had just completed the new f-string .format module (…wow…) and this is a very similar concept for the print() function, I suppose.

Avatar image for pmkdatar

pmkdatar on Jan. 22, 2023

Nice explaination about sep and end arguments

Avatar image for Martin Breuss

Martin Breuss RP Team on Jan. 25, 2023

Glad the course has been useful :) And there’s a lot of fun stuff you can do when you dive deeper into using print() and its arguments!

Avatar image for rwelk

rwelk on Feb. 15, 2024

Short and sweet, easy to understand. Thank you.

Become a Member to join the conversation.