Python variables

Last updated Aug 08, 2021

Python Variables

A Python variable is a symbolic name that is a reference or pointer to an object. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Let's understand by an example

var1 = 'Hello' var2 = 78

var3 = 104.77

print(type(var1))

print(type(var2))

print(type(var3))

 

In the above code, I had printed the type of three different variables of different data types  - string, integer, and float respectively.

 

Python Type Conversion

The process of converting the value of one data type (integer, string, float, etc.) to another data type is called type conversion

In python type conversion is of two types:-

  1. Implicit type conversion - In this type of conversion, the Python interpreter automatically converts one data type to another without the help of any user involvement.
    1. Explicit type conversion - Here the data type is changed manually by the user as per their requirement of the program.

 

Let's take an example of Type Conversion:-

var1 = "98"

var2 = 78

var3 = 104.77

var4 = "45"

print(int(var1)+int(var4))



 

 

143