What is Variable in Python?

Share Your Love

Python Variables:

Variable is a container to store data.

Variable is a name of memory location where data stored in a particular address.

Creating Variables:

Python has no syntax for declaring a variable.

When we declare the variable the value or data assign on it directly.

x = 5
y = "John"

The above code the type of x means here is integer and type of y is string.

When you assign data directly any variable in python the type of variable is defined on that time.

x = 4       # x is of type int
x = "Sally" # x is now of type str

The above code output is:


Because x shows me recent value or data.

Python Casting:

If you want to specify the data type of a variable, then we are using inbuilt python functions.

x = str(4)    # x will be '4'
y = int(7)    # y will be 7
z = float(9)  # z will be 9.0


The output of above code:


Python Return The Type Of Variable:

In python if you want to check the type of variable is it when assign some values on it, then how?

x = 5
y = "John"

Here in above code returns the type of variable by help of this function called type(var_name).

So, the output is:

<class 'int'>
<class 'str'>

What is Single Quote and Double Quote Means?

In python string variables are declared in single and double quotes:

x = "John"
#double quotes are the same as single quotes:
x = 'John'

The output of above code:


Case-Sensitive In Python:

In python the variable names are case-sensitive, means:

a = 2
A = 4

The above code plays, will not overwrite with data because both are different on python point.

But, in some case we write:

a = 56
a = "asdf"

Then here a first play the role of Integer then it play the role of String.

So, in coding the recent value will be assigned on it and take granted.

Share Your Love
Avatar photo
Lingaraj Senapati

Hey There! I am Lingaraj Senapati, the Founder of lingarajtechhub.com My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.

Articles: 429

Newsletter Updates

Enter your email address below to subscribe to our newsletter