Welcome to Day 14! As we continue our DevOps journey, today's focus is on Python's data types and structures. Python is not just for developers; it's a powerhouse for DevOps engineers too. Let's get started!
Understanding Data Types in Python ๐
Data types are crucial since they dictate what kind of operations can be performed on data. In Python, everything is an object, and these types are just classes.
Numeric: These include integers, floats, and complex numbers. Each holds different kinds of numerical values.
Sequential: This includes strings, lists, and tuples, perfect for holding an ordered collection of items.
Boolean: The truth or falsity of an expression โ either
True
orFalse
.Set: An unordered collection with no duplicate elements.
Dictionaries: These are unordered key-value pairs, super-efficient thanks to their O(1) time complexity.
Checking the data type is easy. For example:
your_variable = 100 print(type(your_variable)) # <class 'int'>
Diving Into Data Structures ๐๏ธ
Efficient data handling is key in programming, and Python simplifies the learning curve.
Lists: Like arrays but better because they can hold different data types and are mutable.
Tuples: Ordered collections like lists but immutable. Once you create a tuple, it's set in stone.
Dictionaries: These are my go-to for key-value storage. They're like cheat sheets for storing and retrieving data.
Task Time: Lists, Tuples, and Dictionaries ๐
Difference Between List, Tuple, and Set
Lists are mutable, which means I can change them. They're like shopping lists; you can always add another item.
Tuples are immutable, akin to a barcode on a product โ unchangeable once it's there.
Sets are unordered and don't allow duplicates. Think of them as your unique collection of tools where you only need one of each.
For the hands-on task, I experimented with each type. I tried adding, removing, and updating elements in lists and sets (well, not in tuples because you know, they're immutable). And then I checked their types, modified them, and printed the results.
Dictionaries in Action ๐
Here's the dictionary I created:
fav_tools = { 1: "Linux", 2: "Git", 3: "Docker", 4: "Kubernetes", 5: "Terraform", 6: "Ansible", 7: "Chef" }
To print my favorite tool, let's say 'Docker', I used:
print(fav_tools[3]) # Docker
Expanding the Cloud Providers List โ๏ธ
Started with a list:
cloud_providers = ["AWS", "GCP", "Azure"]
Adding 'Digital Ocean' and sorting the list:
cloud_providers.append("Digital Ocean") cloud_providers.sort() print(cloud_providers) # ['AWS', 'Azure', 'Digital Ocean', 'GCP']
๐จ Creativity in Documentation: I've included screenshots in my repository, showing the Python shell with all the manipulations for a visual and practical understanding of these concepts.
๐ Reflections: Today reinforced how Python's simplicity and power are essential in the DevOps toolkit. These data types and structures are not just academic; they're the building blocks for scripts and automation that make our lives easier. #Day14 #PythonInDevOps #DevOpsDiary #CodingFun #PythonDataTypes #PythonDataStructures ๐๐จโ๐ป
Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.
You can connect with me at: https://www.linkedin.com/in/davendersingh/