OneBite.Dev - Coding blog in a bite size

check if array is empty in python

Code snippet on how to check if array is empty in python

  bool_is_empty = len(a) == 0

This code checks if an array, a, is empty in Python. First, a boolean variable, bool_is_empty, is created. This variable will store the outcome of the check. Next, the len() function is used to take the length of the array a. This is compared to 0 using the comparison (==) operator. If the length of the array is 0, then the array is empty, and the bool_is_empty variable is assigned True. Otherwise, bool_is_empty is assigned False. The comparison can then be used to determine whether the array is empty or not.

python