Tuesday, February 20, 2018

best way to check if a list is empty in Python3

Do it with:
if not a:
    print("a is an empty list.")

instead of:

if len(a):
    print("a is an empty list.")

Reference: Official Python programming recommendations
See the discussions on Stack Overflow

No comments: