- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 best way to check if a list is empty in Python?
The best way is to use not operator on list object. If list is empty it returns true, otherwise false.
>>> L1= >>> not L1 True >>> L1=[1,2] >>> not L1 False
Another method is to check if length of list is zero which means it is empty
>>> L1= >>> len(L1) 0 >>> L1=[1,2] >>> len(L1) 2
- What is the best way to handle list empty exception in Python?
- How to check if a list is empty in Python?
- What is the most elegant way to check if the string is empty in Python?
- What is the correct way to check if String is empty in Java?
- How to check if a C# list is empty?
- Check if a list is not empty in MongoDB?
- Python - Check if dictionary is empty
- What is the best way to check capacity in Java?
- What is the best way to log a Python exception?
- Python Pandas - Check if an interval is empty
- Check if a HashMap is empty in Java
- Python program to check whether a list is empty or not?
- Python - Check if a list is contained in another list
- How to check if a string is empty in Kotlin?