What is a Variable in Python?

A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing.

Python Variable Types

Every value in Python has a datatype. Different data types in Python are Numbers, List, Tuple, Strings, Dictionary, etc. Variables in Python can be declared by any name or even alphabets like a, aa, abc, etc.

In this tutorial, we will learn,

How to Declare and use a Variable

Let see an example. We will define variable in Python and declare it as "a" and print it.

a=100 
print (a)

Re-declare a Variable

You can re-declare Python variables even after you have declared once.

  • or "buckets" where information can be maintained and referenced. Like any other programming language Python also uses a variable to store the information.
  • Variables can be declared by any name or even alphabets like a, aa, abc, etc.
  • Variables can be re-declared even after you have declared them for once
  • In Python you cannot concatenate string with number directly, you need to declare them as a separate variable, and after that, you can concatenate number with string
  • Python constants can be understood as types of variables that hold the value which can not be changed. Usually Python constants are referenced from other files. Python define constant is declared in a new or separate file which contains functions, modules, etc.
  • Types of variables in Python or Python variable types : Local & Global
  • Declare local variable when you want to use it for current function
  • Declare Global variable when you want to use the same variable for rest of the program
  • To delete a variable, it uses keyword "del".