What is variables? how to use variable in python | Python Variables



variable in python

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.

Example

a = 10  #integer
f  = 10.2  #float
name = "abc" #string
print(a)
print(f)
print(name)

Output

10

10.2

abc



Common Rules for variables name

  1. Variable names are case-sensitive.
  2. Variable names must begin with a letter or underscore.
  3. A variable name can only contain alphanumeric characters and underscore such as (a-z, A-Z,0-9, and _).
  4. A variable name can not contents space.
  5. Reserved words cannot be used as variable names.



Keywords

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.


False class finally is return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in raise

Next Post Previous Post
No Comment
Add Comment
comment url