Variables in Python
Variable in python is used to a reserved a location in memory. This variable is used to store data. Variable are play an important role in a programming language. When we storing data in a variable in python the processor automatically assigns a data type to the variable according to the data.
The data type of variable in python
Python Numbers:
Python numbers are integer floating-point numbers and complex numbers. The integer is a negative and positive number without a decimal point for example 7,8,-22, or 234. Floating point numbers are numbers that have decimal points for example 2.454, -3.566, etc. The complex number is written in the form of a+bj etc.
#Number variable
a = 25
#floating point variable
b = 9.344
#complex Variable
c = 1+4j
Python List:
Python List is used to storing more than one data. The list can store multitype data in a single list. We have not defined a separate list for each data type. The list is the mutable data type. It has unlimited capacity. List use square brackets and separate each data by comma(,). For Example...
#List Variable
a = [12,23,2.345,true,false]
Python Tuple:
Python tuples are the immutable data type. It stores information once it creates and cannot be changed later. Python tuple can be read but cannot change. Python Tuple is readable only. Tuple uses Paranthese brackets and separates each data by comma(,). Example...
#Tuple Variable
tpl = (12,23,2.345,true,false)
Python String :
Python string is used to store a named spell, quotes, etc. The string is close in the quotation marks (""). We can use single or double-quotes. Here is an example.
#String Variable
str = "Hello World!"
str2 = 'Hello World!'
How to assign a value to a variable in python:
Assigning a value to a variable in python is very easy. Here is an example.
a = 25
In this above example, a is the name of a variable you can name your variable whatever you want.
In Programming the equal sign (=) is used to assign value to a variable. This equal sign is known as the Assignment operator. The 25 is the value we want to store in the variable. There also other types of variables in python but we will discuss them later.
