Python Free Tutorial

Variable is defined as the reserved memory location to store the value. Various data types like Numbers, List, Tuple, Strings, Dictionary, etc are used in python and hence these values are stored in the variables. We start with an identifier which is the name of our variable then equal sign and finally a value.

>>> a = 5  # a is variable 
>>> print(a)

output :5

We can re-declare the variable even though it is declared above. It stores the newly assigned value replacing the old value assigned to it.

>>> a= 10
>>> a =56      # reassigning the value to variable
>>> print (a)

output: 56

Let’s try something different:

>>> a = 6
>>> del a 
>>> print (a)

     Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     NameError: name 'a' is not defined

Here, we delete variable using the command del . In the above example, we deleted variable a, and when we proceed to print it, we get error “name ‘a’ is not defined” which means you have deleted the variable.

Rules of Declaring variables
  1. A variable name must start with a letter or the underscore character
  2. A variable name cannot start with a number
  3. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  4. Variable names are case-sensitive (age, Age and AGE are three different variables)

This page is contributed by Diwas & Sunil . If you like AIHUB and would like to contribute, you can also write an article & mail your article to . See your articles appearing on AI HUB platform and help other AI Enthusiast.

About Diwas

🚀 I'm Diwas Pandey, a Computer Engineer with an unyielding passion for Artificial Intelligence, currently pursuing a Master's in Computer Science at Washington State University, USA. As a dedicated blogger at AIHUBPROJECTS.COM, I share insights into the cutting-edge developments in AI, and as a Freelancer, I leverage my technical expertise to craft innovative solutions. Join me in bridging the gap between technology and healthcare as we shape a brighter future together! 🌍🤖🔬

View all posts by Diwas →


  1. Thanks for a marvelous posting! I quite enjoyed reading it, you could be a great
    author. I will be sure to bookmark your blog and
    will eventually come back later on. I want to encourage one to continue
    your great posts, have a nice evening!

Leave a Reply

Your email address will not be published. Required fields are marked *