Python Data Types and Data Structures for DevOps

Python Data Types and Data Structures for DevOps

#Day 14 of 90daysofdevops

Hi Friends,

In this blog, I will try to explain data types and data structure with some hands on.

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: your_variable=100 type(your_variable)

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 fundamental 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 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

Tasks

  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 ordered data.

  • Lists are mutable. Can be modified after creation.

  • Lists are declared with square brackets.

      list_data=[1,2,3.5,[-4,5.6],"git","docker"]
      print(list_data)
      list_data[5]="Jenkins"
      print("List after change made")
      print(list_data)
    

Tuple:

  • A tuple is an ordered collection of data.

  • Tuples are immutable.

  • cannot be modified after creation.

  • Tuples are enclosed within parentheses.

    Let's understand with below code:

Set:

  • A set is an unordered collection.

  • Sets are mutable and have no duplicate elements.

  • Sets are represented in curly brackets.

  • It stores multiple values in a single variable.

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

3. Create a List of cloud service providers.

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

Thank you for reading this blog.Happy Learning!!!!!

You can follow me on LinkedIn for my daily updates:- linkedin.com/in/parimal-pradhan-b62021168

To read my previous blog on Python click here:https://hashnode.com/edit/clhxutpz9000209l4cxvt2jyj

Great initiative by the #trainwithshubham community. Thank you Shubham Londhe

Did you find this article valuable?

Support Parimal Pradhan by becoming a sponsor. Any amount is appreciated!