python variable

Declaring Variable and Assigning Values

Python does not bound us to declare variable before using in the application. It allows us to create variable at required time.
We don't need to declare explicitly variable in Python. When we assign any value to the variable that variable is declared automatically.
The equal (=) operator is used to assign value to a variable.
Eg:
p var
Multiple Assignment
Python allows us to assign a value to multiple variables in a single statement which is also known as multiple assignment.
We can apply multiple assignments in two ways either by assigning a single value to multiple variables or assigning multiple values to multiple variables. Lets see given examples.

1. Assigning single value to multiple variablesEg:

  1. x=y=z=50  
  2. print iple  
  3. print y  
  4. print z  


2.Assigning multiple values to multiple variables:Eg:

  1. a,b,c=5,10,15  
  2. print a  
  3. print b  
  4. print c  

No comments:

Post a Comment