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

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands 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 your subtitle preferences 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 refer to our video player troubleshooting guide for assistance.

Writing Output to the Console

00:00 In this lesson, you will learn how to write some output that you collected in your script back to the console to give some output to the user. You will do this using the print() function.

00:12 So if you remember the script that you wrote before, if you just execute it the way that it is now, it correctly collects the input, converts it to an integer, but it doesn’t tell me what’s the result of this calculation that it does internally. And if you do this inside of a script, you need to be explicit.

00:30 If you do this inside of the Python interpreter, you might be used to that, that if you do a calculation in here, you automatically get the output displayed.

00:39 But if you want to do this in a script, then you need to wrap what you want to display inside of the print() function. You can say print() and then pass it this calculation that has as an output a number and then displays it back to the console.

00:56 So, this is how you display output to the console.

01:01 Now, when I run this script again, it is still going to collect the input. I can type something in here, it’s going to convert it to an integer, do the calculation, and then also print the output back to the console.

01:16 And this is how you can use the print() function to display all sorts of output back to the console for your users. In the next lesson, you will learn how you can adapt and customize how print() displays the output to the console a little bit using some keyword arguments to the function.

Become a Member to join the conversation.