Variables in Python

1. Definition of a variable

A variable is a logical name given to physical memory location in the RAM or HDD. When a variable is declared or created (assigning value to a variable), Python interpreter reserves some space to that variable and the space is named as the name of the variable. How much space to be reserved will be depended on the data type of the value assigned to the variable.

Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.

Other Definition

variable is something that holds a value that may change. In simplest terms, a variable is just a box that you can put stuff in. You can use variables to store all kinds of stuff, but for now, we are just going to look at storing numbers in variables.

lucky = 7

print (lucky)

7

This code creates a variable called lucky and assigns to it the integer number 7. When we ask Python to tell us what is stored in the variable lucky, it returns that number again.

"Variables" by wikibooks is licensed under CC BY-SA 4.0