Skip to main content

Command Palette

Search for a command to run...

Python Data Types and Data Structures for DevOps

Published
3 min readView as Markdown
Python Data Types and Data Structures for DevOps

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.

  1. Numeric types: These include integers, floats, and complex numbers.

  2. Boolean type: This is a binary data type that can have one of two values, either True or False.

  3. Sequence types: These include strings, lists, and tuples.

  4. Dictionary type: This is an unordered collection of key-value pairs.

  5. Set type: This is an unordered collection of unique elements.

  6. None type: This is a special type in Python that represents the absence of a value.

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.

  1. 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.

  2. 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.

  3. 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 Handson and put screenshots as per your understanding.

Lists:

  • Lists are defined using square brackets [].

  • Lists are mutable, which means you can change the values of elements in a list.

  • Lists can contain duplicate values.

  • Lists are ordered, meaning that the elements of a list are stored in a particular order.

  • Lists allow indexing and slicing operations.

Tuple

  • Tuples are defined using parentheses ().

  • Tuples are immutable, which means you cannot change the values of elements in a tuple.

  • Tuples can contain duplicate values.

  • Tuples are ordered, meaning that the elements of a tuple are stored in a particular order.

  • Tuples allow indexing and slicing operations.

Set

  • Sets are defined using curly braces {} or the set() function.

  • Sets are mutable, which means you can change the values of elements in a set.

  • Sets cannot contain duplicate values.

  • Sets are unordered, meaning that the elements of a set are not stored in a particular order.

  • Sets do not allow indexing or slicing operations.

Dictionary

Add element to the list

More from this blog

DevOps

19 posts