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 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=100type(your_variable)
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
Difference between List, Tuple, and set.
Lists:
Mutable: Lists are mutable, meaning you can change their content after they are created.
Ordered: Lists maintain the order of elements.
Allows Duplicates: Lists can contain duplicate elements.
Defined with Square Brackets []: Lists are created using square brackets
[]
.
Now if we need to modify our list we can do that as well.
Suppose we need to replace 1 with 10 then we can do it.
Tuples:
Immutable: Tuples are immutable, meaning once created, their content cannot be changed.
Ordered: Tuples maintain the order of elements.
Allows Duplicates: Tuples can contain duplicate elements.
Defined with Parentheses (): Tuples are created using parentheses
()
.
Sets:
Mutable (But Elements are Immutable): Sets are mutable, but the elements contained in a set must be immutable (e.g., strings, numbers, tuples).
Unordered: Sets do not maintain the order of elements.
Doesn't Allow Duplicates: Sets cannot contain duplicate elements. If you try to add a duplicate element, it will be ignored.
Defined with Curly Braces {}: Sets are created using curly braces
{}
.
Tasks :
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.
We can take input from users as well to add that provider to the list.
Thank you for joining me on this journey into DevOps! Your curiosity is the driving force behind this exploration. If you found value in these insights, I'm thrilled! Keep the DevOps flame alive, and stay tuned for more exciting adventures in the world of technology. Happy Learning! 🚀✨"
"Closing the gap between us—let's connect and make our virtual bond stronger on social media!
Click on -Umesh Salunkhe