Re: Usage of the __and__ method



theju wrote:

I've two objects (both instances of a class called Person) and I want
to use the __and__ method and print the combined attributes of the two
instances.

r = p and q
print r.print_name()

The above output in both cases is giving me a doubt if __and__ method
is over-ridable or not?

You cannot customize the logical 'and'. The __and__() method is used to
implement the binary and '&'. Change your code to

r = p & q
print r.print_name()

Peter
.