I have two examples:
a = [1,2,3]
b = 4
print (a.__len__())
print (len(a))
print(b.__add__(4))
print (b + 4)
I guess my question is, is there a difference when using __len__
magic method versus the built in len()
method? The only time I see people use __len__
is when trying to trying to find the length of an object of a user-created class.
Same with other dunder methods, such as __str__
, or __add__
I never seem them used outside of a class or OOP in general.