Table of contents
- Python Data Types:
- 1.Difference between List, Tuple, and Set
- 2. 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" }
- 3. Create a List of cloud service providers eg.
- 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
Python Data Types:
1.Difference between List, Tuple, and Set
1. A list is an ordered collection of similar or different types of items separated by commas and enclosed within brackets [ ].
The Set is an unordered collection of unique items. Set is defined by values separated by commas inside braces { }.
Tuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified.
2. A list refers to a data structure of a non-homogenous type that functions to store various elements in columns, multiple rows, and single rows.
A tuple also refers to a data structure of the non-homogenous type that functions to store various elements in columns, multiple rows, and single rows.
A set also refers to a data structure of the non-homogenous type, but it stores various elements in a single row.
3. Lists allow various duplicate elements.
Tuple allows various duplicate elements.
The set does not allow any duplicate elements.
4. We can create a list using the list() function.
We can create a tuple using the tuple() function.
We can create a set using the set() function.
5. List is mutable. It means that a user can make any changes to a list
Tuple is immutable. It means that a user can’t make any changes to a tuple.
The Set is mutable. It means that a user can make any changes to a set.
6. If we want to create an empty list, we use: l=[]
If we want to create an empty tuple, we use:
t=()
If we want to create an empty set, we use:
a=set()
b=set(a)
2. 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" }
First, create a dictionary and then print it. To execute a python file python followed by file name.
3. Create a List of cloud service providers eg.
cloud_providers = ["AWS","GCP","Azure"]
To access items from a list, we use the index number (0, 1, 2 ...). So here I print Azure [2]
4. Write a program to add Digital Ocean to the list of cloud_providers and sort the list in alphabetical order
Just add Digital_Ocean to the list and sort(by default it is set to ascending order) the cloud provider by using the sort() function.