How to check list is empty or not in Python

If list contains zero elements or length of list is zero is known as empty list.

We can check whether list is empty or not using below methods

1. Declare empty list

a=[] #Empty list

type(a)

2. Check list is empty or not by using len function of list.

len(x) 0

3. Using if condition(Pythonic way)

if not a: print('a is empty list')

a is empty list

How to check list is empty or not in Python

4. Using comparison operator(==)

if a==[]: print('a is empty list')

a is empty list

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: