Skip to main content

Command Palette

Search for a command to run...

Python Data Types & Data Structures for DevOps

Day 14 for 90daysOfDevOps

Published
2 min readView as Markdown
Python Data Types & Data Structures for DevOps
S

Hello, I am sumit and currently pursing my final year of graduation with IT stream from JSPM BSIOTR Wagholi Pune. I am currently learning DevOps with TrainWIthShubham. I have prior knowledge of Java, JSP, Servlet, SQL and Data structure also.I am a hard worker, smart and quick learner.

Python 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

Data Structure

Python provides several built-in data structures, which are fundamental for organizing and storing data efficiently. Here are some commonly used data structures in Python:

  1. Lists:

    • A mutable, ordered sequence.

    • Created using square brackets [].

    • Example:

        pythonCopy codemy_list = [1, 2, 3, 'hello', 4.5]
      
  2. Tuples:

    • An immutable, ordered sequence.

    • Created using parentheses ().

    • Example:

        pythonCopy codemy_tuple = (1, 2, 3, 'world', 4.5)
      
  3. Sets:

    • An unordered collection of unique elements.

    • Created using curly braces {} or the set() constructor.

    • Example:

        pythonCopy codemy_set = {1, 2, 3, 4, 4, 5}
      
  4. Dictionaries:

    • A collection of key-value pairs.

    • Created using curly braces {} or the dict() constructor.

    • Example:

        pythonCopy codemy_dict = {'name': 'John', 'age': 25, 'city': 'New York'}
      
  5. Strings:

    • A sequence of characters.

    • Immutable.

    • Created using single (') or double (") quotes.

    • Example:

        pythonCopy codemy_string = "Hello, Python!"
      
  6. Arrays (from the array module):

    • A more compact way to represent arrays of numeric values.

    • Example:

        pythonCopy codefrom array import array
        my_array = array('i', [1, 2, 3, 4, 5])
      
  7. Deque (from the collections module):

    • Double-ended queue.

    • Supports fast appends and pops from both ends.

    • Example:

        pythonCopy codefrom collections import deque
        my_deque = deque([1, 2, 3, 4, 5])
      
  8. Stacks (using lists):

    • LIFO (Last-In, First-Out) data structure.

    • Implemented using lists.

    • Example:

        pythonCopy codemy_stack = [1, 2, 3]
        my_stack.append(4)  # push
        top_item = my_stack.pop()  # pop
      
  9. Queues (using lists or queue module):

    • FIFO (First-In, First-Out) data structure.

    • Example (using lists):

        pythonCopy codemy_queue = [1, 2, 3]
        my_queue.append(4)  # enqueue
        front_item = my_queue.pop(0)  # dequeue
      
    • Example (using queue module):

        pythonCopy codefrom queue import Queue
        my_queue = Queue()
        my_queue.put(1)  # enqueue
        front_item = my_queue.get()  # dequeue