Variables in Python refers to an object — an item or element that is stored in the memory.

They are containers used for storing data values . The values can be string, numeric or any combination of alphanumeric characters.

In Python we can use an assignment statement to create new variables and assign specific values to them. 

  • Variable declaration is implicit in Python, which means variables are automatically declared and defined when they are assigned a value the first time. 
  • Variables must always be assigned values before they are used in expressions as otherwise it will lead to an error in the program. 
  • Wherever a variable name occurs in an expression, the interpreter replaces it with the value of that particular variable.

Examples:

  • gender = 'M' 
  • message = "Keep Smiling" 
  • price = 987.9

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.