Articles → Python → Variables In Python

Variables In Python






What Are The Variables?





How To Declare A Variable?




  1. Specifying the variable name
  2. Followed by assignment operator i.e. ‘=’.
  3. Followed by value.


name = "gyan"
age = 30



Multiple Assignment Of Variables In Python




x= y = z = 2

print(x,y,z)




Picture showing the output of Multiple assignment of variables in python

Click to Enlarge



x= y = z = 2
x = x + 1
print(x,y,z)




Picture showing the output of Multiple assignment of variables in python

Click to Enlarge




Declaring Multiple Variables In One Line




width, height = 20,40

print("width:",width)
print("height:",height)




Picture showing the output of Declaring multiple variables in one line

Click to Enlarge


Rules Of Creating Variables




  1. Variable names are case sensitive.
  2. Variable name should only contain alphabet, numbers and underscore.
  3. Keywords should not be used as variable name.
  4. Variable name should start with alphabet or underscore.



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, January 31, 2019
 
Updated On  -  Tuesday, March 26, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250