
Syntax: Printing
Examining values at any time with the Python print function.
Printing Outputs
One of the most fundamental parts of learning programming in any computer language is learning how to output values from a program so that the validity of those values can be confirmed. Python includes an easy to use function which provides that functionality. Look below at the code from the previous exercise:
print("Hello, World!")
The print( ... ) part of the code above tells Python to call a function named print and to output the message written in between the parentheses to the interpreter. print is a built-in function that is always available in Python. print is a function you will get a lot of practice with as it is incredibly useful for outputting messages and values from your applications.
Time to Practice
-
Open your Python interpreter.
-
Use the
printfunction to output the following messages:- Print out the greeting, "Hello there!"
- Print out a message introducing yourself to someone by telling your name.
- Print out a message letting someone know your age.
HINT*: Click here for a hint
>"Hello there!" "My name is Obi-Wan Kenobi." "I am 30 years old."
SOLUTION*: Click here for an example solution
print("Hello there!")
> "Hello there!"
print("My name is Obi-Wan Kenobi.")
> "My name is Obi-Wan Kenobi."
print("I am 30 years old.")
> "I am 30 years old."
Once you have completed the above, you are ready to move on to the next exercise!