Python Data types and Data structures for DevOps Engineers.

Data Types:

  • Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data.

  • Since everything is an object in Python programming, data types are classes and variables are instances (objects) of these classes.

  • Python has the following data types built-in by default: Numeric(Integer, complex, float), Sequential(string,lists, tuples), Boolean, Set, Dictionaries, etc

    To check what is the data type of the variable used, we can simply write: variable = 100

    type(variable)

Python Data Types (with Examples) - JC Chouinard

Data Structures:

Data Structures are a way of organizing data so that it can be accessed more efficiently depending on the situation. Data Structures are fundamentals of any programming language around which a program is built. Python helps to learn the fundamentals of these data structures in a simpler way as compared to other programming languages.

  • Lists: Python Lists are just like the arrays, declared in other languages which is an ordered collection of data. It is very flexible as the items in a list do not need to be of the same type

  • Tuple: Python Tuple is a collection of Python objects much like a list but Tuples are immutable in nature i.e. the elements in the tuple cannot be added or removed once created. Just like a List, a Tuple can also contain elements of various types.

  • Dictionary: Python dictionary is like hash tables in any other language with the time complexity of O(1). It is an unordered collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, Dictionary holds the key: value pair. Key-value is provided in the dictionary to make it more optimized.

TASK 1:

Give the Difference between List, Tuple, and Set. Do Hands-on and put screenshots as per your understanding.

List: A list is a collection of items that are ordered and changeable. Lists are written with square brackets and items are separated by commas. Lists can contain any type of item, including other lists.

Tuple: A tuple is a collection of items that are ordered and unchangeable. Tuples are written with parentheses and items are separated by commas. Tuples can contain any type of item, including other tuples.

The set is an unordered collection of data types that is iterable, mutable, and has no duplicate elements. The order of elements in a set is undefined though it may consist of various elements.

TASK 2:

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

    To print the values of all the keys in the above dictionary, I used for loop and iterate the keys to get all the values.

    for i in fav_tools:

    print(fav_tools[i])

To Print the fav_tool,

Task - 3: Create a List of cloud service providers.

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.

Thank you for reading the blog.....!!!!!

Happy learning..:)

0
Subscribe to my newsletter

Read articles from RAKESH REVASHETTI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

RAKESH REVASHETTI
RAKESH REVASHETTI

I'm Rakesh, a DevOps engineer who enjoys automation, continuous integration and deployment. With good hands-on experience in DevOps & cloud technology, i'm proficient in various tools and technologies related to infrastructure automation, containerization, cloud platform, monitoring and CI/CD.