

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the best way to handle list empty exception in Python?
List is an ordered sequence of elements. Individual element in list is accessed using index starting with 0 and goes up to length-1. If index goes beyond this range, IndexError exception is encountered.
In following example, an infinite loop is used to pop one element at a time. As loop tries to go even after last element is popped, IndexError exception will be encountered. We trap it using try – except mechanism.
a=[1,2,3] while True: try: b=a.pop() print (b) except (IndexError): break
- Related Questions & Answers
- What is the best way to log a Python exception?
- What is best way to check if a list is empty in Python?
- What is the best way to handle a Javascript popup using Selenium Webdriver?
- What is the best way to stop Brain Drain?
- What is the best way to earn money online?
- What is the most elegant way to check if the string is empty in Python?
- What is the best way to concatenate strings in JavaScript?
- What is the best way to check capacity in Java?
- What is the best way to run all Python files in a directory?
- How to handle an exception in Python?
- How to handle Python exception in Threads?
- What is the best way to initialize a JavaScript number?
- What is the best way to remove an item from a Python dictionary?
- What is the best way to compare two strings in JavaScript?
- What is the best way to add an event in JavaScript?
Advertisements