Signup/Sign In
LAST UPDATED: MARCH 3, 2020

Implementing Stack in Python

    We all know about Stack data structure, right? For those of you who do not know, Stack is a data structure which is used to store data in a structured way.

    In a Stack, data which is stored at the end, is the data which is removed first. This is behavious of Stack is also known as Last in First Out or First in Last Out.

    A stack data structure generally has the following 3 methods:

    1. push(): For adding data to the stack.

    2. pop(): For removing data from the stack.

    3. size(): To check the size of stack.

    4. isEmpty(): To check if the stack is empty or not.

    A few other points to remember are:

    1. You cannot add or remove data randomly from a Stack.

    2. The addition and removal of data elements happen from a single side.

    So let's write a simple class Stack to implement stack in python.

    Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS