Table of contents
PermalinkData Types:
Data types in Python refer to classifying or categorizing data objects based on their characteristics and behavior.
They define the type of values variables can hold and determine the performed operations on those values.
Python has several built-in data types, including :
Numeric data types:
int, float, complex
String data types:
str
Sequence types:
list, tuple, range
Mapping data type:
dict
Boolean type:
bool
PermalinkData Structures
A data structure structures the data. 'Data + structures,' says it all.
It is a storage unit that organizes and stores data in a way the programmer can easily access.
There are 4 inbuilt data structures in Python namely:
Lists
, Dictionaries
, Tuples
& Sets
.
Lists:
A list is an ordered sequence of elements. It is a non-scalar data structure and is mutable (the ability of objects to change their values) in nature.
A list can contain distinct data types.Lists can be accessed with the help of the index by enclosing the index within square brackets.
Tuples:
It is also a non-scalar type defined in Python. Just like lists, it is also an ordered sequence of characters but tuples are immutable by nature.
This means any modification is not allowed with this data structure.Sets:
It is an unordered collection of objects without any duplicates. This can be done by enclosing all the elements within curly braces.
We can also form sets by using type casting via the keyword “set”. Elements of a set must of immutable data types.
Set doesn’t support indexing, slicing, concatenation & replication. We can iterate over elements using the index.Dictionary:
A dictionary is an unordered sequence of key-value pairs. Indices can be of any immutable type and are called keys. This is also specified within curly braces.
We can access the values with the help of unique keys associated with them.
Permalink📌Task-01
- Give the Difference between List, Tuple and Set. Do Handson and put screenshots as per your understanding.
List:
A list is an ordered sequence of elements. It is a non-scalar data structure and is mutable (the ability of objects to change their values) in nature.
A list can contain distinct data types.Lists can be accessed with the help of the index by enclosing the index within square brackets.
- Tuple:
It is also a non-scalar type defined in Python. Just like lists, it is also an ordered sequence of characters but tuples are immutable by nature.
This means any modification is not allowed with this data structure.
- Set:
It is an unordered collection of objects without any duplicates. This can be done by enclosing all the elements within curly braces.
We can also form sets by using type casting via the keyword “set”. Elements of a set must of immutable data types.
Set doesn’t support indexing, slicing, concatenation & replication. We can iterate over elements using the index.
Permalink📌Task02
- Create the 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"
}
Output
Permalink📌Task-03
- Create a List of cloud service providers eg.
Write a program to addDigital Ocean
to the list of cloud_providers and sort the list in alphabetical order.
cloud_providers = ["AWS","GCP","Azure"]
Output:
Thank you for reading this article. Happy learning😊!!!