Python Variables

A Detailed Tutorial on Python Variables:

Our previous tutorial explained us about Python and its Installation process in detail.

In this tutorial, we will have an in-depth look at the Python Variables along with simple examples to enrich your understanding of the python concepts.

Read through our Entire Python Series for a clear understanding of the various concepts involved in Python.

Watch the VIDEO Tutorial

Role and Importance of Variables in Python

Python Variables

A variable means holding a value or reserving memory location to store values. In variable, you can store any kind of values by using appropriate data types.

In Python, variables do not need a declaration to reserve memory space. The “variable declaration” or “variable initialization” happens automatically when we assign a value to a variable.

How to Declare and use a Variable

To declare a variable we use “=” to assign the value to a variable.

Example:

We will declare the following variable and print it.

Number= 25
Name = “Kiran”
B= 3.5
print (Number)
print(Name)
print (B)

python variables example

Re-declare a Variable

We can re-declare a variable at any point of time even after you have declared it once.

Example:

Name = Python
print(Name)

python re-declare variable example

Multiple Assignment

In Python, we can assign the same value to multiple variables at once.

Example:

x = y = z = "SoftwareTestingHelp"
print (x)
print (y)
print (z)

python multiple assignment example

We can also assign multiple values to multiple variables.

Example:

a, b, c = 5, 3.2, "Hello"
print (a)
print (b)
print (c)

python multiple assignment example 2

Hope you would have understood the concept of Python Variables in detail from this tutorial.

Watch out our upcoming tutorial to know more about Python Data Types!!

PREV Tutorial | NEXT Tutorial