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

Table of contents

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 actually classes and variables are instance (object) 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=100type(your_variable)

Data Structures -

Data Structures are a way of organizing data so that it can be accessed more efficiently depending upon 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 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.

Hands-On Task -
Give the Difference between List, Tuple and set. Do Handson and put screenshots as per your understanding.

List -
The list is a datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.

Lists are mutable i.e. it can be converted into another data type and can store any data element in it.

List can store any type of element.

The list is a datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.

  • List are mutable i.e. it can be converted into another data type and can store any data element in it.

  • List can store any type of element.
    Ordered: Elements have a specific order.

  • Mutable: Elements can be changed, added, or removed.

  • Allows Duplicates: Can contain repeated elements.

  • Syntax: Defined with square brackets [].

    Tuple -
    Tuple is a collection of Python objects much like a list. The sequence of values stored in a tuple can be of any type, and they are indexed by integers. Values of a tuple are syntactically separated by ‘commas. Although it is not necessary, it is more common to define a tuple by closing the sequence of values in parentheses. The main characteristics of tuples are –
    1.Tuple is an immutable sequence in python.

  • 2.It cannot be changed or replaced since it is immutable.

  • 3.It is defined under parenthesis ().

  • 4.Tuples can store any type of element.

Set -
In Python, Set is an unordered collection of data type that is iterable, mutable, and has no duplicate elements. The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set. The main characteristics of set are –

  • 1.Sets are an unordered collection of elements or unintended collection of items In python.

  • 2.Here the order in which the elements are added into the set is not fixed, it can change frequently.

  • 3.It is defined under curly braces {}

  • 4.Sets are mutable, however, only immutable objects can be stored in it.

  • "Thanks for reading! If you enjoyed my blog, feel free to share and leave a comment!"

0
Subscribe to my newsletter

Read articles from AVINASH SARJERAO POWAR directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

AVINASH SARJERAO POWAR
AVINASH SARJERAO POWAR