Python Variables

If we were talking about any other programming language then we would have to see that we have to use some keyword to declare the variable or we have to tell what is the type of data or object that is being stored but python programming is not like that.

Welcome To Python Programming

What are variables?

Variables are nothing, It is just a name in a memory area, used for storing data.

Python Variable Declaration

We do not use any keyword to declare a variable in python.

To declare a variable in python, we have to take a name and we will use the equal operator to assign values or data.

a = 90 
b = 90.9 
c = "Python Variable" 
print(a) # Output: 90
print(b) # Output: 90.9
print(c) # Output: Python Variable

Multiple values assign to multiple variables in a single line

If we want to store multiple values inside multiple variables in one line. Follow This

a,b,c = 90,89.98,"python" 
print(a)  #Output: 90
print(b)  #Output: 89.98
print(c)  #Output: python
The same values assigned to multiple variables in a single line

If we want to store the same value inside multiple variables in one line. Follow This

a=b=c=d=100 
print(a)  #Output: 100
print(b)  #Output: 100
print(c)  #Output: 100
print(d)  #Output: 100
Rules for Python Variables

There are some rules for declaring the name of a variable in python.

  1. The variable name never starts with a number.
  2. A variable name can be started with a letter and an underscore.
  3. Variable name can only consist letters(A-Z,a-z), numbers(0-9),underscore(_).

Some Wrong variable names

7a = 89  #Not following rule number 1 and rule number 2              
%t = 45  #Not following rule number 1 , 2 , 3
t5!5 = 89 #Not following rule number 3

Check Your Knowledge

Python Variable Quiz

Read More Educational Posts