THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This tutorial explains multiple ways to check List is empty or not
Empty List contains zero elements in size and is denoted as []
For example, an Empty list can be declared as follows
list=[]
In Real applications, Data comes from an API and returns a List.
There are multiple ways we can check List is empty or not.
Here is an example
list=[];
if not list the:
print("Empty List")
Output:
Empty List
len
function returns the size of a list, Returns zero for an empty list.Here is an example
if len(list) == 0:
print("Empty List")
use ==
operator that compares an empty list
if list == []:
print("Empty List")
🧮 Tags
Recent posts
Julia examples - Variable Type Nim example - Convert String to/from the Int How to get length of an array and sequence in Nim? Nim environment variables - read, set, delete, exists, and iterate examples? How to convert from single character to/from string in Nim?Related posts