Variables in Python
In most programming languages, a variable is a named location used to store data in the memory. Each variable must have a unique name called an identifier. It is helpful to think of a variable as a container that holds data that can be changed later throughout programming.
Python interpreter allocates memory based on the values data type of variable, different data types like integers, decimals characters, etc. can be stored in these variables.
Declaring Variable and Assigning Values
In Python, variables do not need a declaration to reserve memory space. The "variable declaration" or "variable initialization" happens automatically when we assign a value to a variable.
The equal (=) operator is used to assign value to a variable.
The left side operand of = operator is the name of a variable, and right side operand is value.
Common Rules for variables name
- Variable names are case-sensitive.
- Variable names must begin with a letter or underscore.
- A variable name can only contain alphanumeric characters and underscore such as (a-z, A-Z,0-9, and _).
- A variable name can not contents space.
- Reserved words cannot be used as variable names.
Python Keywords are special reserved words that convey a special meaning to the compiler/interpreter. Each keyword has a special meaning and a specific operation. These keywords can't be used as variables. Following is the List of Python Keywords.