# Day 14 - Python Data Types and Data Structures for DevOps

## New day, New Topic... Let's learn along 😉

### Data Types

Data types are the classification or categorization of data items. They represent the kind of value that determines what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes, and variables are instances (objects) of these classes.

Python has the following data types built-in by default:

* **Numeric**: `int`, `float`, `complex`
    
* **Sequence**: `str`, `list`, `tuple`
    
* **Boolean**: `bool`
    
* **Set**: `set`
    
* **Dictionary**: `dict`
    

To check the data type of a variable, you can use the `type()` function:

```python
your_variable = 100
print(type(your_variable))  # Output: <class 'int'>
```

### Data Structures

Data structures are ways of organizing data so that it can be accessed more efficiently, depending upon the situation. They are fundamental to any programming language, forming the backbone around which a program is built. Python provides a simple way to learn these data structures.

#### Lists

Python lists are like arrays in other languages. They are an ordered collection of data and are very flexible since the items in a list do not need to be of the same type.

Example:

```python
my_list = [1, "hello", 3.14, True]
print(my_list)
```

#### Tuples

Python tuples are similar to lists but are immutable. This means that once a tuple is created, its elements cannot be added or removed.

Example:

```python
my_tuple = (1, "hello", 3.14, True)
print(my_tuple)
```

#### Dictionaries

Python dictionaries are like hash tables in other languages, with a time complexity of O(1) for lookups. They are unordered collections of data values that store data in key-value pairs.

Example:

```python
my_dict = {"name": "Tushar", "age": 24, "country": "India"}
print(my_dict)
print(my_dict["name"])  # Output: Tushar
```

### Tasks

#### 1\. Difference between List, Tuple, and Set

* **List**: Ordered, mutable, allows duplicate elements.
    
* **Tuple**: Ordered, immutable, allows duplicate elements.
    
* **Set**: Unordered, mutable, does not allow duplicate elements.
    

#### 2\. Dictionary Task

Create the following dictionary and use dictionary methods to print your favorite tool just by using the keys of the dictionary.

```python
fav_tools = {
    1: "Linux",
    2: "Git",
    3: "Docker",
    4: "Kubernetes",
    5: "Terraform",
    6: "Ansible",
    7: "Chef"
}
print(fav_tools[3])  # Output: Docker
```

#### 3\. List Task

Create a list of cloud service providers, add "Digital Ocean" to the list, and sort the list in alphabetical order.

```python
cloud_providers = ["AWS", "GCP", "Azure"]
cloud_providers.append("Digital Ocean")
cloud_providers.sort()
print(cloud_providers)  # Output: ['AWS', 'Azure', 'Digital Ocean', 'GCP']
```

### Conclusion

Understanding Python data types and data structures is crucial for any DevOps engineer. They form the basis of efficient data manipulation and processing. With these fundamentals in place, you can build more robust and efficient automation scripts, tools, and infrastructure management solutions.

Happy coding!

~ Tushar Ranjan🙂
