Tasks
Give the Difference between List, Tuple and set.
List:
List is an ordered collection of elements.
Lists are mutable, which means you can change, add, or remove elements after creation.
Elements in a list are enclosed in square brackets
[ ]
.Lists allow duplicate elements.
Lists are useful when you need a dynamic collection that can be modified during the program's execution.
my_list = ["apple", "banana", "cherry"] print(my_list)
Tuple:
Tuple is an ordered collection of elements, similar to a list.
Tuples are immutable, which means you cannot modify their elements after creation.
Elements in a tuple are enclosed in parentheses
( )
.Tuples allow duplicate elements.
Tuples are useful when you want to create a collection that should not be changed or to represent fixed data.
thistuple = ("apple", "banana", "cherry") print(thistuple)
Set:
Set is an unordered collection of unique elements.
Sets are mutable, meaning you can add or remove elements after creation.
Elements in a set are enclosed in curly braces
{ }
.Sets do not allow duplicate elements; each element is unique.
Sets are useful when you want to perform mathematical set operations like union, intersection, etc., or when you need to ensure uniqueness of elements in a collection.
thisset = {"apple", "banana", "cherry"} print(thisset)
Create below Dictionary and use Dictionary methods to print your favourite tool just by using the keys of the Dictionary.
Create a List of cloud service providers eg.
If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐ #devops #90daysofdevop #python