0% found this document useful (0 votes)
14 views5 pages

Python Stack

Uploaded by

guccisama03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Python Stack

Uploaded by

guccisama03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LO: To implement stacks using Python.

To explain the various operations


SUCCESS CRITERIA

Stack: A stack is a linear data structure in which all the insertion


and deletion of data / values are done at one end only. It is also To write the function
header.
known as LIFO(Last In First Out) data structure.
➢Insertion / Deletion in stack can only be done from top.
To create a function
➢Insertion in stack is known as a PUSH operation. body.
➢Deletion from stack is known as POP operation in stack.
Applications:
To call a function.
1. String reversal
2. Factorial of number
3. Infix to postfix To analyze the
Stacks are implemented in Python using list. elements in a function
definition.
Append() method is used to implement push operation and pop()
method is used to implement pop operation.
The definition of
Overflow: A condition in which a user is trying to add an element to a full stack. function and its
structure is explained in
the next slide
Underflow: A condition in which a user is trying to remove an element from an empty stack.

A sample program to implement stack and the output is given below:


LO: To create functions based on given scenario.
SUCCESS CRITERIA

Function: A function is a programming block of codes which is used to perform a single, related To write the function
header.
task. It only runs when it is called. We can pass data, known as parameters, into a function. A
function can return data as a result.
To create a function
body.

To call a function.

To analyze the
elements in a function
definition.
A sample function definition and call of stack push operation of adding details of city.

Function header always starts with the keyword def and ends with a colon(:)
Function definition consists of function header and function body.
A sample function definition and call of stack push operation of adding details of city.

You might also like