Quotations in Variables?

Hi!
Why do I have to include quotations for text but not numbers when writing out a variable?

Ex:
greeting_message = "Welcome to Codecademy!"
current_exercise = 5

thanks!

Variable Codecademy

Hello, @sophie247, and welcome to the forums!

The quotation marks tell the computer to treat the value as a string. The computer needs to know what the data type of the value is, so it can be treated accordingly. For example:

a = 5
b = 2
c = '5'
d = '2'
print(a + b) # 7 ('+' adds numbers)
print(c + d) # 52 ('+' concatenates strings)

You can check the type of a value using type(). Here’s a few:

print(type(5))
print(type('5'))
print(type(5.5))
print(type(True))

Output:

<class ‘int’>
<class ‘str’>
<class ‘float’>
<class ‘bool’>

1 Like

If it ends up being needed you can also change the type of value that a variable contains.
You can use:
int() to change the value to an integer
str() to change the value to a string

You will learn about how to use these later in the course though.

1 Like