Python len() built-in function
Example
Return the the number of items of an object:
>>> len('hello')
# 5
>>> len(['cat', 3, 'dog'])
# 3
Test of emptiness
len
, but prefer direct boolean evaluation.
>>> a = [1, 2, 3]
# bad
>>> if len(a) > 0: # evaluates to True
... print("the list is not empty!")
...
# the list is not empty!
# good
>>> if a: # evaluates to True
... print("the list is not empty!")
...
# the list is not empty!