Every programing lanaguage have their own set of Data Types. Therefore, every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

- Python Numbers
- Python Lists
- Python Tuples
- Python Strings
- Python Dictionary
- Python Set

There are interegers, floating number and complex numers in the category of Python Numbers.These data types are defined as int, float, and complex classes.

You can use the **type()** function to know which class a variable or a value belongs to.

Similarly, the **isinstance()** function is used to check if an object belongs to a particular class.

**Integer** : It can be of any lenght and limited by the memory available.

**Floating Point Number**: The floating point numbers are accurate up to 15 decimal places.

**Complex Number**: It is written x + yj, where x is the real part and y is the imaginary part.

Let's see the example to understand the data types in Python.

In [3]:

```
a = 5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
```

**List**is basically an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type.

Items separated by commas are enclosed within brackets [ ].

In [1]:

```
a = [1, 2.2, 'python']
```

In [2]:

```
a = [5,10,15,20,25,30,35,40]
# a[2] = 15
print("a[2] = ", a[2])
# a[0:3] = [5, 10, 15]
print("a[0:3] = ", a[0:3])
# a[5:] = [30, 35, 40]
print("a[5:] = ", a[5:])
```

Tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified.

Tuples are used to write-protect data and are usually faster than lists as they cannot change dynamically.

It is defined within parentheses () where items are separated by commas.

In [5]:

```
t = (5,'program', 1+3j)
# t[1] = 'program'
print("t[1] = ", t[1])
# t[0:3] = (5, 'program', (1+3j))
print("t[0:3] = ", t[0:3])
```

In [6]:

```
s = "This is a string"
print(s)
s = '''A multiline
string'''
print(s)
```

Dictionary is an unordered collection of key-value pairs.

Dictionary is generally used when you are dealing with huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to retrieve the value.

In Python, dictionaries are defined within braces {} with each item being a pair in the form key:value. Key and value can be of any type.

In [8]:

```
d = {1:'value','key':2}
print(type(d))
print("d[1] = ", d[1]);
print("d['key'] = ", d['key']);
```

In [9]:

```
a = {5,2,3,1,4}
# printing set variable
print("a = ", a)
# data type of variable a
print(type(a))
```

The variable a, b and c are three sides of a triangle. Then,

**Formula Of Triangle**

s = (a+b+c)/2
area = √(s(s-a)*(s-b)*(s-c))

In [1]:

```
# Python Program to find the area of triangle
a = 5
b = 6
c = 7
# Uncomment below to take inputs from the user
# a = float(input('Enter first side: '))
# b = float(input('Enter second side: '))
# c = float(input('Enter third side: '))
# calculate the semi-perimeter
s = (a + b + c) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
```

In the above program you can even take the input ( the values for 3 sides of triangle from the user. Taking input from the user is already explained in "Part-1")

In [11]:

```
n=int(input("Enter number: "))
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
print("Reverse of the number:",rev)
```

Dolly Solanki

Learning Numpy - Simple Tutorial For Beginners - NumPy - Array Creation Routines Part 5

Learning Numpy - Simple Tutorial For Beginners - NumPy - Array Attributes Part 4

Learning Numpy - Simple Tutorial For Beginners - NumPy - Data Types Part 3

Learning Numpy - Simple Tutorial For Beginners - NumPy - Ndarray Object Part 2