What does age = 30 do in Python?
Options
- It compares age with 30 and prints True or False on screen
- It creates a variable called age that refers to the value 30 (Correct option)
- It defines a function called age that always returns 30
- It prints the number 30 on the screen and stores nothing
Answer
Creates a variable named age that refers to the value 30
Why
A variable is a name that points to a value, so you can use the value later.
The single = means assign (store), not compare. Comparing uses ==.
In Python you do not declare the type. age simply refers to the integer 30, and later it could refer to something else.
Remember
variable = value stores the value under a name.