Sunday, January 13, 2019

python - How do I check if a list is empty?




For example, if passed the following:



a = []



How do I check to see if a is empty?


Answer



if not a:
print("List is empty")


Using the implicit booleanness of the empty list is quite pythonic.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...