Conditionals accept more then just true/false ?

Could someone explain why this works?

obj = bpy.context.active_object
if (obj.data.materials) : print(“Object has at least one material slot”)
else : print(“Object has no material slots”)

I python the an non empty list/dictorary string evaluates as True. It is also considered good practice just check it like so.
So no if len(my_list) > 0: and similar code, just simple if my_list:



a = []
b = [2, 3, 4]
print(bool(a))
print(bool(b))
print(bool(bpy.data.objects))

The below is from the python Style guide PEP8

For sequences, (strings, lists, tuples), use the fact that empty sequences are false.



Yes: if not seq:
     if seq:

No: if len(seq):
    if not len(seq):