Mastery10Basic output (print) in Python

The main output function is called print(). This function basically lets you make your output look nicer and easier to read.

So you can basically take your input and save it in our variable “n” so you can reuse it using your output function print().

n = input(“Please enter your age: “)

Once we have our input, which is the user’s name. We can take it and print it.

n = input(“Please enter your age: “)

print(n)

But that isn’t too fun since we are basically repeating what the user said. We will put it inside the stringthat restates the obvious.

n = input(“Please enter your age: “)

print(“The user is ” + n + ” years old.”)

This looks better right? The correct answer is no because we didn’t convert our input into a string.

n = input(“Please enter your age: “)

print(“The user is ” + str(n )+ ” years old.”)

Overall, there isn’t much to the print() function, you just have to remember the type of data you are printing and handle it accordingly.

CC BY 4.0 Mastery10 by 5nbpppkkyj is licensed under a Creative Commons Attribution 4.0 International License.