mercredi 10 février 2021

How to override if of an object?

I have created a class A:

class A:
    def __init__(self, items):
        self.items = items

a=A([1,2])

I want to make it such that I can do if a to get True if there are items in the list and False otherwise. I couldn't find a way to do that. Overriding __eq__ was for comparing the object with another.

Aucun commentaire:

Enregistrer un commentaire