The is_empty() method returns a Boolean value that describes whether or not the stack is empty. This video demonstrates how to evaluate the equivalency of the stack and an empty list to accomplish this purpose.
- [Instructor] The last method we'll add to our stack class…is the is empty method.…This should return a Boolean value describing…whether or not the stack is empty.…To do this, all you need to do is test for a quality…between our stack instance which is represented…as a list and an empty list.…So, in code that looks like…return self dot items double equals empty list.…If our list is equivalent to an empty list,…that would return true, but if our list is not equivalent…to an empty list, that would return false.…
So I'm going to save our file…and we'll go back to the terminal.…I'll fire up the interpreter here.…Create our stack object,…and let's get right to testing this new is empty method.…Now the first time we run this after having created…our stack object, we expect that the is empty method…would return true, which it does.…So let's now push a string with apple in it on to our stack.…
We can double check that here.…My, whoops, typo, my stack dot items.…A list with only apple in it which is what we expect,…and now if we do my stack dot is empty, we should get false.…
- Abstract types and data structures
- Stacks as a linear abstract data type
- Creating the Stack class and its methods
- Adding items to the top and bottom of a stack
- Creating the Queue class and its methods
- Manipulating items in a queue
- Creating the Dequeue class and its methods
- Adding and removing items from a dequeue
Skill Level Advanced
Learning the Python 3 Standard Librarywith Kathryn Hodge2h 9m Intermediate
What you should know1m 26s
1. Abstract Data Types and Data Structures
2. The Stack
3. The Queue
4. The Deque
Next steps1m 43s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.