Python Tutorial @ Home

#### Data Structures In Python

Data Structures In Python

# Data Structures In Python

Data structures are a way of organizing and storing data so that they can be accessed and worked efficiently. They define the relationship between the data and the operations that can be performed on the data.

There are many various kinds of data structures defined that make it easier for the data scientists and the computer engineers, to concentrate on the main picture of solving larger problems rather than getting lost in the details of data description and access.

Here, you will learn about the various Python data structures and see how they are implemented:

Abstract Data Type and Data Structures

Primitive Data Structures

• Integers
• Float
• Strings
• Boolean

Non-Primitive Data Structures

• Arrays
• Lists
• Tuples
• Dictionary
• Sets
• Files

### Abstract Data Type and Data Structures

Data structure helps us to focus on the bigger picture rather than getting lost in the details. This is known as data abstraction.

Data structures are actually an implementation of Abstract Data Types or ADT. This implementation requires a physical view of data using some collection of programming constructs and basic data types.

Generally, data structures can be divided into two categories in computer science: primitive and non-primitive data structures. The former are the simplest forms of representing data, whereas the latter is more advanced: they contain the primitive data structures within more complex data structures for special purposes.

### Primitive Data Structures

These are the most primitive or basic data structures. They are the building blocks for data manipulation and contain pure, simple values of data. Python has four primitive variable types:

integers
float
strings
boolean

Let’s go through the primitive data types:

### Integers

You can use an integer represent numeric data, and more specifically, whole numbers from negative infinity to infinity, like 46, 54, or -14.

```# inyegers
x = 7
y = 3

print(x + y)

# Subtraction
print(x - y)

# Multiplication
print(x * y)

# Returns the quotient
print(x / y)

# Returns the remainder
print(x % y)

# Absolute value
print(abs(x))

# x to the power y
print(x ** y)
```

Note that in Python, you do not have to explicitly state the type of the variable or your data. That is because it is a dynamically typed language. Dynamically typed languages are the languages where the type of data an object can store is mutable.

Output:

```10
4
21
2.3333333333333335
1
7
343
>>> ```

### Float

“Float” stands for ‘floating-point number’. You can use it for rational numbers, usually ending with a decimal figure, such as 21.11 or 443.14.

```# Float
x = 2.5
y = 3.6

print(x + y)

# Subtraction
print(x - y)

# Multiplication
print(x * y)

# Returns the quotient
print(x / y)

# Returns the remainder
print(x % y)

# Absolute value
print(abs(x))

# x to the power y
print(x ** y)
```

Note that in Python, you do not have to explicitly state the type of the variable or your data. That is because it is a dynamically typed language. Dynamically typed languages are the languages where the type of data an object can store is mutable.

Output:

```6.1
-1.1
9.0
0.6944444444444444
2.5
2.5
27.07597043574791
>>> ```