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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

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()

Download

Sample Code (.zip)

715 bytes

Download

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!

aniketbarphe on Nov. 7, 2021

Thank You!

doxsee on Nov. 21, 2021

Thanks for highlighting ‘sep’ and ‘end’.

Become a Member to join the conversation.