djtiamme
last year
Djtiammecountry asked

If I write greeting = "Merry Christmas" and then print("greeting"), will it print Merry Christmas?

Kelish Rai
Expert
last year
Kelish Rai answered

It seems there’s a slight confusion about what you're trying to achieve.

Firstly, "greeting" = "Merry Christmas" is incorrect, as you don’t need to enclose variables within quotation marks. The correct syntax would be:

greeting = "Merry Christmas"

This way, greeting is correctly defined as a variable. Whereas Python would treat "greeting" as a string instead.

Similarly, the line print("greeting") won’t print "Merry Christmas" because of the quotation marks.

To correctly print the value of the greeting variable, you should write:

print(greeting)

This will output "Merry Christmas" as expected.

Note: Think of variables as "labels" for values. If you wrap the label in quotes, Python thinks it's just a word, not a label pointing to something else.

Python
This question was asked as part of the Getting started with Python course.