Python Variables:

Variable is a name of a memory loacation to store a value.


Declaration

When you assign a value to variable_name then automatically the memory is assigned for the variable.


Example

  1. var1=200 # int declaration
  2. var2=200.3 # floating point declaration
  3. var3="scanftree" # string declaration
  4.  
  5. print var1
  6. print var2
  7. print var3


Output

200
200.3
scanftree


Multiple Assignment:

Python allows you to assign a single value to several variables simultaneously.

Example:

  1. a = b = c = 10 # approach 1
  2. or
  3. a, b, c =10, 20, "scanftree.com" # approach 2


In the first approach all variables a, b, c are assigned value 10
In the second approach a, b are assigned values 10 and 20 whereas c has been assigned with scanftree.com

  1. var1=100
  2. var2=30.3
  3. var3="scanftree"
  4.  
  5. print var1
  6. print var2
  7. print var3

In the next chapter you are going to learn data-types of python