๐ Day 14 Task: Python Data Types and Data Structures for DevOps ๐
New day, New Topic.... Let's learn along ๐
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 instances (objects) 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: ๐ your_variable = 100 ๐ type(your_variable)
Data Structures ๐๏ธ Data Structures are a way of organizing data so that it can be accessed more efficiently depending upon 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 a 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.
Tasks ๐ 1๏ธโฃ Give the Difference between List, Tuple, and Set: Lists:
Ordered collection
Mutable (can be changed after creation)
Can contain duplicate elements ๐ท Screenshot 1: [List]
Tuple:
Ordered collection
Immutable (cannot be changed after creation)
Can contain duplicate elements ๐ท Screenshot 2: [Tuple]
Set:
Unordered collection
Mutable (can be changed after creation)
Contains only unique elements ๐ท Screenshot 3: [Set]
2๏ธโฃ Create below 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" } ๐ To print my favorite tool: ๐ print(fav_tools[4]) # Output: "Kubernetes"
3๏ธโฃ Create a List of cloud service providers e.g.: cloud_providers = ["AWS", "GCP", "Azure"]
4๏ธโฃ Write a program to add Digital Ocean to the list of cloud_providers and sort the list in alphabetical order: ๐ cloud_providers.append("Digital Ocean") ๐ cloud_providers.sort()
That's it for today! Keep coding and have fun with Python's data types and data structures! ๐๐
#Python #DataTypes #DataStructures #DevOps #LearningIsFun