Light Mode
Dark Mode
Proper way to check if sequence is empty.

PEP8: For sequences, (strings, lists, tuples), use the fact that empty sequences are false.

You also can use it with dict and set.

Yes:

if not seq:
if seq:

No:

if len(seq):
if not len(seq):

No:

if seq == []:
if seq != []:
Created: March 1, 2014, 11:42 a.m.
Updated: May 11, 2016, 4:20 a.m.
18
31
User avatar
Cjkjvfnby