
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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