Beginner Guide to Check Python Tuple, List, Dict is Empty or not – Python Tutorial

By | December 25, 2019

Python tuple, list and dict are widely used to save data in python application. How to check they are empty? To answer this question. We will write some examples to explain it for you in this tutorial.

An empty tuple, list and dict

In python script, we can create an empty tuple, list and dict like this:

tuple = ()
list = []
dict = {}

Python tuple, list and dict are empty, which means there is not any data in them.

How to check tuple, list and dict is empty or not

The most simplest way is:

if tuple:
    print("tuple is not empty")
if list:
    print("list is not empty")
if dict:
    print("dict is not empty")

While, you also can check them by their length. Here is an example:

if len(tuple) > 0:
    print("tuple is not empty")
if len(list) > 0:
    print("list is not empty")
if len(dict) > 0:
    print("dict is not empty")

Leave a Reply

Your email address will not be published. Required fields are marked *