![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
Advertisements