Day 14 Task: Python Data Types and Data Structures for DevOps

Day 14 Task: Python Data Types and Data Structures for DevOps

Data Types in Python:

Python, being dynamically typed, allows variables to be assigned without declaring their type explicitly. Here are some fundamental data types in Python:

  • Integer (int):

    Represents whole numbers, positive or negative, without any decimal point.

  • Float (float):

    Represents real numbers with a decimal point or in exponential form.

  • String (str):

    Represents sequences of characters, enclosed within single, double, or triple quotes.

  • Boolean (bool):

    Represents truth values, either True or False.

  • List:

    Ordered collection of items, mutable and can contain elements of different data types.

  • Tuple:

    Ordered collection of items, immutable and can contain elements of different data types.

  • Dictionary (dict):

    Collection of key-value pairs, unordered and mutable.

  • Set:

    Unordered collection of unique items, mutable but does not allow duplicates.

Data Structures in Python:

Data structures in Python provide efficient ways of storing and manipulating data. Let's explore some commonly used ones:

  • Lists:

    • Ordered and mutable, allowing for easy modification.

    • Ideal for storing collections of homogeneous items.

        my_list = [1, 2, 3, 'hello', True]
      
  • Tuples:

    • Immutable sequences, making them suitable for storing fixed collections.

    • Generally used for heterogeneous data.

        my_tuple = (1, 'apple', True)
      
  • Dictionaries:

    • Unordered collection of key-value pairs, providing fast lookup.

    • Keys must be unique and immutable, while values can be of any data type.

        my_dict = {'name': 'John', 'age': 30, 'city': 'New York'}
      
  • Sets:

    • Unordered collection of unique elements.

    • Useful for operations like union, intersection, and difference.

        my_set = {1, 2, 3, 4, 5}Tasks
      

Tasks

  1. Give the Difference between List, Tuple and set. Do Handson and put screenshots as per your understanding.

  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 eg. cloud_providers = ["AWS","GCP","Azure"]

    Write a program to add Digital Ocean to the list of cloud_providers and sort the list in alphabetical order.

In conclusion, Python's simplicity, versatility, and robust ecosystem make it an indispensable asset in DevOps, empowering teams to streamline processes, enhance collaboration, and drive innovation in software development and operations. Embrace Python, and unlock the full potential of DevOps!