Skip to main content

Command Palette

Search for a command to run...

Python Data Types and Data Structures for DevOps

Published
3 min read
Python Data Types and Data Structures for DevOps
S

I have 10+ years of experience in Project Management across a range of industries including Oil & Gas, IT, Retail, and Rail Transportation, I have developed a proven track record in delivering results while maintaining a positive and proactive approach to work responsibilities.

As I look to the future, I am excited to pivot my career towards the field of Technology as a Scrum Master with a DevOps Engineer skill-set. To achieve this goal, I am committed to acquiring a range of key skills, knowledge, and certifications including SAFe Scrum Master, SAFe DevOps Practitioner, and expertise in a variety of DevOps tools such as Linux, Git & GitHub, Networking, CI/CD (Jenkins), Docker, AWS, Terraform, Kubernetes, Prometheus, Grafana, Go, and Python. I am eager to bring my experience and passion to a new role as a DevOps Engineer and to make a valuable contribution to any team.

I am excited about the opportunities ahead and look forward to bringing my expertise, enthusiasm, and positive attitude to a new role. Thank you for taking the time to learn more about me, and I welcome the opportunity to connect and explore potential collaborations.

Data Types

Python has several built-in data types that allow you to store and manipulate different kinds of data. Data types in Python form the basis for storing and manipulating data in various formats. Python also allows one to create custom data types using classes and objects through Object Oriented Programming (OOP). Here are the fundamental data types in Python: numeric; set; boolean; mapping; & sequence. See my previous blog explaining each of the Data Types in Python.

Data Structures

Flow Chart of Data Structures in Python

Data structures are used to organize and store data efficiently, allowing you to perform various operations on that data. Have a look at my previous blog which explains the Non-Primitive data structures which are built-in in Python.

Primitive: allows you to store only single data types values such as integers, float, string, and boolean.

Non-Primitive: allows you to store multiple data type values such as lists, sets, stacks, etc.


Task 1: Give the Difference between List, Tuple and Set. Do Handson and put screenshots as per your understanding.

In Python lists, tuples, and sets are 3 types of data non-primitive built-in Data Structures.

Lists: an ordered collection of items which can contain different data types and are mutable. It is defined by "[]" square brackets and it allows you to index (starting from 0 indexes, being the 1st item in the list) and slice (a process of accessing a sub-sequence of a sequence by specifying a starting and ending index[excluding the element at the ending index]).

     # List of Popular Clouds
cloud_list = ["AWS","Azure","GCP","Oracle"] #list defined with values

    # Index - print only a certain index
print(cloud_list[1]) # the output is "Azure"

    # Slice - print only the subset of the list
 print(cloud_list[0:3]) # the output is 'AWS','Azure','GCP'

Tuple: an ordered collection of items similar to lists, however, tuples are immutable. It is defined by "()" parentheses and it allows you to index (starting from 0 indexes, being the 1st item in the list).

    # Example of a Tuple
tuple_cloud_list = ("AWS", "Azure", "GCP", "Oracle")

    # Index - print only a certain index
print(tuple_cloud_list[0]) # the output is "AWS"

Set: Represents an unordered collection of unique elements. They are useful for tasks involving membership testing, removing duplicates, and performing mathematical set operations.

Membership refers to the act of determining whether an element belongs to a set.

It is defined by either "{}" curly braces or by the use of a "set()" function and is mutable. Slicing and Indexing cannot be performed in a set directly.

    # Example of a Set with {}
cloud_set = {"AWS", "Azure", "GCP", "Oracle"}

    # Example of a Set with ()
cloud_set = set(("AWS", "Azure", "GCP", "Oracle"))

Task 2: Create a Dictionary of your favourite DevOps tools and use Dictionary methods to print your favourite DevOps tool just by using the keys of the Dictionary.

    #created a Dictionary
fav_tools = {
    1:"Linux",
    2:"Git",
    3:"Docker",
    4:"Kubernetes",
    5:"Terraform",
    6:"Ansible",
    7:"Chef"
}
print("My favourite DevOps tool is", fav_tools[1])

# OUTPUT ---> "My favourite DevOps tool is Linux"

Task 3: Create a List of cloud service providers eg. Write a program to add "Digital Ocean" to the list of cloud providers and sort the list in alphabetical order.

# List of some Cloud Providers created
cloud_providers = ["AWS","Azure","GCP","Oracle"]
print(cloud_providers)

     # to add (append) to a list use below command with .append
cloud_providers.append("Digital Ocean")
print(cloud_providers)

    # Sort the list in Alphabetical order using the sort() method
cloud_providers.sort()
print(cloud_providers) # list will be printed in Alphabetical order

I appreciate your busy time reading this short blog. As I continue with my journey to learn and acquire the skill set of a DevOps Engineer, I will share what I learn. Thank you.

Happy Learning!


Sam Samarullah

LinkedIn

Previous Blog