PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Stack & Queue

← All stacks

Theory

96/268

Stack & Queue

Stack = LIFO. Use a list: append + pop(). Queue = FIFO. Use collections.deque: append + popleft() (list pop(0) is slow).

Board — stack [1,2,3] pop → 3. Queue Asha,Ravi popleft → Asha first.

Stack & Queue — output — stack pop B (LIFO) then queue Asha (FIFO).

Exam tip

LIFO vs FIFO + which Python type.

Example

# Stack & Queue
from collections import deque
stack = []
stack.append("A")
stack.append("B")
print("stack pop", stack.pop())
q = deque(["Asha", "Ravi"])
print("queue", q.popleft())

Stack & Queue — output: stack pop B (LIFO) then queue Asha (FIFO).

Short notes

  • Stack LIFO : append/pop
  • Queue FIFO : deque popleft
  • Traplist.pop(0) is O(n)

Questions

1

Explain Stack & Queue as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Stack & Queue?

Previous← Magic methodsNextPySpark MLlib →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.