Day 14 - Python Data Types and Data Structures for DevOps

Hey there! ๐
I'm Tushar Ranjan, a DevOps Engineer passionate. Currently, on a learning adventure, I'm here to share my journey and Blogs in the world of cloud and DevOps.
๐ ๏ธ My focus? Making sense of AWS services, improving CI/CD, and diving into infrastructure as code. Whether you're fellow interns or curious enthusiasts, let's grow together in the vibrant DevOps space.
๐ Connect with me for friendly chats, shared experiences, and learning moments. Here's to embracing the learning curve and thriving in the exciting world of AWS DevOps Technology!
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,complexSequence:
str,list,tupleBoolean:
boolSet:
setDictionary:
dict
To check the data type of a variable, you can use the type() function:
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:
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:
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:
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.
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.
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๐




