Python Data Types and Data Structures for DevOps

Python Data Types and Data Structures for DevOps

Difference between List, Tuple and Set.

List, Tuple and Set are all data structures in Python used to store collections of elements. They differ in their properties and usage.

List:

  • A List is an ordered collection of elements enclosed in square brackets [ ].

  • Lists are mutable, which means their elements can be changed or updated after they have been created.

  • Lists can store duplicate values and can be used to hold any type of data.

  • Lists can be accessed using indexing and slicing.

Example:

Tuple:

  • A Tuple is an ordered collection of elements enclosed in parenthesis ( ).

  • Tuples are immutable, which means their elements cannot be changed or updated after they have been created.

  • Tuples can store duplicate values and can be used to hold any type of data.

  • Tuples can be accessed using indexing and slicing.

Example:

Set:

  • A Set is an unordered collection of unique elements enclosed in curly braces { }.

  • Sets are mutable, which means their elements can be changed or updated after they have been created.

  • Sets do not store duplicate values and can be used to hold any type of data.

  • Sets cannot be accessed using indexing and slicing.

Example:

Dictionary

  1. Dictionary:
  • A Dictionary is an unordered collection of key-value pairs enclosed in curly braces { }.

  • Keys in a Dictionary must be unique and immutable, such as strings or numbers, while values can be of any data type, including another Dictionary.

  • Dictionaries are mutable, which means their key-value pairs can be added, removed or updated after they have been created.

  • Dictionaries can be accessed using keys.

  1. Create a Dictionary and use Dictionary methods to print your favorite tool just by using the keys of the Dictionary.

  1. Create a List of cloud service providers eg.
cloud_providers = ["AWS","GCP","Azure"]
  1. Write a program to add Digital Ocean to the list of cloud_providers and sort the list in alphabetical order.

THAT'S ALL FOR TODAY'S LEARNING I HOPE YOU LEARN SOMETHING FROM THIS BLOG