Writing Output to the Console
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.
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.
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.
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.