Programming: Getting started

Variables and values

To print() the value contained in a variable, write:

print(message)

Do not put quote marks around the variable name.

Run the following code in an online Python console, or through VS Code on your own computer.

This will output whatever is stored in the memory location identified by the name message, i.e. it will output the value stored in message.

message = "Hello, World!"
print()
print("print the value contained in the variable named message\n")
print(message)
print("\n")

If we put quote marks around the variable name, then whatever characters are between the quote marks will be output, i.e. the variable name will be output, not the contents of the variable.

print()
print("print the name message\n")
print("message")
print("\n")