# Python Data Types

## A variable can hold values of different data types. While declaring a variable we do not need to define the data type. A variable can hold values of different data types. While declaring a variable we do not need to define the data type.

## Standard Data Types

Python has five standard data types,

## Numbers

Number data type stores numeric values from, python support three types of numerical types,

• Integer
• float
• complex

#### Integer

Integer data type stores whole values, integer may be positive, negative or zero(-∞, 0, +∞). We can find the type of object using type() function.

Example:

``````A = 57
print(A, "This is an example for Integer Data type")
print("The type of object is:", type(A))``````

Output:

``````57 This is an example for Integer Data type
The type of object is: <class 'int'>``````

#### float

Float data type is used to store floating-point numbers. We can use float() function to return floating-point numbers.

Example:

``````A = 35.7
B = float(12)
print(A, "This is an example for Integer Data type")
print("The type of object is:", type(A))
print(B)``````

Output:

``````35.7 This is an example for Integer Data type
The type of object is: <class 'float'>
12.0``````

#### Complex

A complex value contain a real part and a imaginary part, we can access the real part by using real() function and imaginary pat can be accessed by imag() function. complex() function is used to import complex values. To use complex() function we need to import cmath library.

Example:

``````A = 5
B = 7
D = complex(A, B)
print(D)
print(type(D))
print("The Real part is:", D.real)
print("The Imaginary part is:", D.imag)``````

Output:

``````(5+7j)
<class 'complex'>
The Real part is: 5.0
The Imaginary part is: 7.0``````

## String

A String in python can be defined as single quotes, double quotes or in triple quotes. We can concatenate two strings using + operator. To repeat a string values more than one times * operator is used.

Example:

``````A = "Neural Beast"
B = "Always Deliver More than Expected"
print(type(A))
print(A + "", B)
print(A * 2)``````

Output:

``````<class 'str'>
Neural Beast Always Deliver More than Expected
Neural BeastNeural Beast``````

## List

A list can be created using square brackets[] and the values inside is separated with comma. We can change the values in python.

Example:

``````mylist = ["keyboard", "mouse", "monitor"]
print(type(mylist))
print(mylist)``````

Output:

``````<class 'list'>
['keyboard', 'mouse', 'monitor']``````

## Tuple

Tuple is just like list, to create a tuple rounded brackets() are used, to separate vales comma is used. We cannot change the values inside a tuple.

Example:

``````mytuple = ("keyboard", "mouse", "monitor")
print(type(mytuple))
print(mytuple)``````

Output:

``````<class 'tuple'>
('keyboard', 'mouse', 'monitor')``````

## Dictionary

Python Dictionary is an unordered collection. A Dictionary is created with curly brackets{}, it has a keys and values. To assign a key with a value single colon “:” is used. To separate a key and value comma is used. We can change the values in a dictionary.

Example:

``````dict = {"Name" : "Neural Beast", "Tutorial" : "Python Tutorial"}
print(type(dict))
print(dict)``````

Output:

``````<class 'dict'>
{'Name': 'Neural Beast', 'Tutorial': 'Python Tutorial'}``````