Juan Villarreal
last year
Juancountry asked

When writing a variable, do I need quotations? Also, do I need spaces around the equal sign?

Kelish Rai
Expert
last year
Kelish Rai answered

No, you don't need always quotation marks when creating variables. For example,

age = 25

In this case, age is a variable that stores the value 25. Since 25 is a number, we don't need to use quotation marks around it.

However, if you're storing a string in a variable, you must enclose the value with quotation marks. For example,

favorite_food = "Pizza"

Here, favorite_food is a variable, storing the string "Pizza".

As for spaces around the equal sign, Python doesn’t require them, but adding spaces makes the code easier to read:

age=25
age = 25

Here, age=25 works but age = 25 is cleaner and easier to understand.

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