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: you_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 fundamental of these data structures in a simpler way as compared to other programming languages.
Lists: Lists are ordered, mutable sequences of elements. They can contain any type of data and can be modified after creation.
Tuples: Tuples are ordered, immutable sequences of elements. They can contain any type of data, but cannot be modified after creation.
Sets: Sets are unordered collections of unique elements. They can contain any hashable data type and can be modified after creation.
Dictionaries: Dictionaries are unordered collections of key-value pairs. They can contain any hashable data type as keys and any data type as values. They can be modified after creation.
Strings: Strings are ordered, immutable sequences of Unicode characters.
Arrays: Arrays are collections of homogeneous elements of a fixed size. They are more memory-efficient than lists for certain use cases.
Queues: Queues are ordered collections of elements that support adding elements to the back and removing elements from the front.
Stacks: Stacks are ordered collections of elements that support adding elements to the top and removing elements from the top.
## Tasks
1. Give the Difference between List, Tuple and set. Do Handson and put screenshots as per your understanding.
List:
A list is an ordered, mutable collection of elements.
Lists are created using square brackets [] and can contain any type of data.
Lists can be modified after creation, and you can add, remove, or modify elements as needed.
my_list = [1, 2, 3, 4, 5]
Tuple:
A tuple is an ordered, immutable collection of elements.
Tuples are created using parentheses () and can contain any type of data.
Tuples cannot be modified after creation, which means you cannot add, remove, or modify elements once a tuple is created.
my_tuple = ("apple", "banana", "cherry", "orange")
Set:
A set is an unordered, mutable collection of unique elements.
Sets are created using curly braces {} or the set() function, and can contain any hashable data type.
Sets can be modified after creation, and you can add or remove elements as needed.
my_set = {1, 2, 3, 4, 5}
2. 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"
}
3. Create a List of cloud service providers.
Write a program to add Digital Ocean
to the list of cloud_providers and sort the list in alphabetical order.
cloud_providers = ["AWS","GCP","Azure"]
Thank you for reading.