Printing is how we get lines to print to our terminal/console output window. We use the print() function to do this.
2: Printing Output
print() helps you inspect values and explain what your program is doing.
Contributed by Bijou Raj
We can print anything that has a form to be printed in the terminal, from variables, to objects (which we'll cover later).
We can also use one print statement to print out multiple things, as well as multiple lines using the newline \n character.
Using the backslash allows us to print out other escape characters too. " will let us print the ", for example, and \t will give us a tab.
Try it out! Print the first name on one line, the second name on another line, then both names separated by a space on the third.
We can run into type mismatch sometimes when we're printing variables. This can happen because the print() function only takes in strings, so something like this will not work:
We can solve this by using wrappers, or by using f strings. These allow us to insert variables directly into our strings.
When doing this, always keep in mind that we have to match characters. If we open a string with ", we have to close it with ". The same goes for {}, as well as (). Keeping that in mind, try solving the next few exercises.
Print Suzie's age, followed by a tab, followed by her name.
Print out what i is on each iteration. The first output line should be "i is 0" and so on.
Print out the person's age after each year has passed. The output should say: After (number) years, the person is: (age)