Sunday, 13 January 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...