# Day 14 Task: Python Data Types and Data Structures for DevOps

# **Introduction**

Welcome back to our DevOps journey! On Day 14, we'll delve into Python's data types and data structures that are essential for DevOps professionals. We will cover the differences between Lists, Tuples, and Sets, explore Dictionary methods, and work with Lists to enhance your knowledge. 🚀

# **1\. Give the Difference between List, Tuple and set. Do Handson and put screenshots as per your understanding.**

In DevOps, data manipulation is a crucial aspect of scripting and automation. Python provides us with various data types and structures to handle different types of data efficiently. Today, we'll focus on Lists, Tuples, and Sets.

## **Lists**

Lists are versatile and mutable sequences in Python, represented by square brackets `[ ]`. They allow you to store an ordered collection of items. You can add, remove, and modify elements within a list. Let's explore the key differences with an example:

```plaintext
# Creating a List
my_list = [1, 2, 3, 4, 5]

# Append an element to the list
my_list.append(6)

# Remove an element from the list
my_list.remove(3)

# Modify an element
my_list[1] = 42

# List after operations
print(my_list)
```

## **Tuples**

Tuples, denoted by parentheses `( )`, are similar to lists but are immutable, meaning their elements cannot be changed once defined. This makes them suitable for storing fixed data. Here's an example to illustrate:

```plaintext
# Creating a Tuple
my_tuple = (1, 2, 3, 4, 5)

# Attempting to change a tuple element (will result in an error)
# my_tuple[1] = 42

# Tuple as it is
print(my_tuple)
```

### **Sets**

Sets are unordered collections of unique elements enclosed in curly braces `{ }`. They're handy for storing distinct values and performing set operations. Here's a simple set demonstration:

```plaintext
pythonCopy code# Creating a Set
my_set = {1, 2, 3, 4, 5, 5}

# Adding an element to the set
my_set.add(6)

# Set after operations
print(my_set)
```

Now that we understand the differences, let's move on to Dictionaries.

# **2.Create below Dictionary and use Dictionary methods to print your favourite tool just by using the keys of the Dictionary.**

```plaintext
fav_tools = 
{ 
  1:"Linux", 
  2:"Git", 
  3:"Docker", 
  4:"Kubernetes", 
  5:"Terraform", 
  6:"Ansible", 
  7:"Chef"
}
```

Dictionaries are essential for managing key-value pairs. We'll use a dictionary called `fav_tools` to showcase some basic operations:

```plaintext
ofav_tools = {
  1: "Linux",
  2: "Git",
  3: "Docker",
  4: "Kubernetes",
  5: "Terraform",
  6: "Ansible",
  7: "Chef"
}

# Accessing your favorite tool
my_favorite_tool = fav_tools[2]
print(f"My favorite tool is {my_favorite_tool}")
```

# **3.Create a List of cloud service providers eg.**

```plaintext
cloud_providers = ["AWS","GCP","Azure"]
```

# **Write a program to add** `Digital Ocean` **to the list of cloud\_providers and sort the list in alphabetical order.**

In DevOps, we often work with multiple cloud service providers. Let's add "Digital Ocean" to our list of `cloud_providers` and sort it alphabetically:

```plaintext
pythonCopy codecloud_providers = ["AWS", "GCP", "Azure"]

# Adding Digital Ocean
cloud_providers.append("Digital Ocean")

# Sorting the list alphabetically
cloud_providers.sort()

print("Updated Cloud Providers List:")
print(cloud_providers)
```

output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691175098539/5b3bdf18-e0e0-443d-8373-304ad71f1c57.png?auto=compress,format&format=webp align="left")

# **Conclusion**

Today, we've explored key Python data types and data structures that are incredibly useful in DevOps. Understanding these fundamentals will enable you to handle and manipulate data effectively, a crucial skill in the DevOps world. 🛠️

In our next session, we will dive deeper into Python functions and their role in automating DevOps tasks. Stay tuned and keep coding! 💻🔧🌐
