Data Types
Data types are the classification or categorization of data items. It represents the kind of value that tells 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 instance (object) of these classes.
Python has the following data types built-in by default: Numeric(Integer, complex, float), Sequential(string,lists, tuples), Boolean, Set, Dictionaries, etc
To check what is the data type of the variable used, we can simply write:
a=100
type(a)
Data Structures
Data Structures are a way of organizing data so that it can be accessed more efficiently depending on the situation. Data Structures are fundamentals of any programming language around which a program is built. Python helps to learn the fundamentals of these data structures in a simpler way as compared to other programming languages.
Lists Python Lists are just like the arrays, declared in other languages which is an ordered collection of data. It is very flexible as the items in a list do not need to be of the same type
Tuple Python Tuple is a collection of Python objects much like a list but Tuples are immutable in nature i.e. the elements in the tuple cannot be added or removed once created. Just like a List, a Tuple can also contain elements of various types.
Dictionary Python dictionary is like hash tables in any other language with the time complexity of O(1). It is an unordered collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, Dictionary holds the key: value pair. Key-value is provided in the dictionary to make it more optimized
Task 1: The Difference Trio - List, Tuple, Set ๐ญ
List
Definition: A dynamic array that holds an ordered collection of data.
Flexibility: Items in a list can be of different types.
Example Handson:
codemy_list = [1, "DevOps", True, 3.14]
Tuple
Definition: Similar to a list but immutable; elements can't be added or removed once created.
Example Handson:
codemy_tuple = (42, "Automation", False)
Set
Definition: An unordered collection of unique elements.
Example Handson:
codemy_set = {1, 2, 3, 4, 5}
Task 2: Dict Magic - Favorite DevOps Tool ๐ ๏ธ
- Create below Dictionary and use Dictionary methods to print your favourite 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"
}
Python Code:
codefav_tools = { 1: "Linux", 2: "Git", 3: "Docker", 4: "Kubernetes", 5: "Terraform", 6: "Ansible", 7: "Chef" } # Print your favorite tool using keys fav_key = 4 print("My Favorite DevOps Tool:", fav_tools[fav_key])
Task 3: Cloud Provider Sorting Fun โ๏ธ
- Create a List of cloud service providers eg.
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.
Python Code:
codecloud_providers = ["AWS", "GCP", "Azure"] # Add Digital Ocean to the list cloud_providers.append("Digital Ocean") # Sort the list alphabetically cloud_providers.sort() # Print the sorted list print("Sorted Cloud Providers:", cloud_providers)
Results:
- After running the code, the
cloud_providers
list will be updated with "Digital Ocean" and sorted alphabetically.
- After running the code, the
That's it, DevOps superheroes! Dive into these tasks, wield your Python powers, and conquer the DevOps realm! ๐ป๐
#PythonMagic #DevOpsTasks #CodingAdventure