Operator Precedence/Boolean Logic

Steven D'Aprano steve at pearwood.info
Sun Jul 17 12:01:30 EDT 2016


On Mon, 18 Jul 2016 01:58 am, Steven D'Aprano wrote:

> All objects
> can be coerced to strings, using either str() or repr(). If you define
> only one of __str__ or __repr__, Python will use the other.

Er, sorry, that was incoherent. I hit Send too quick, without editing.

What I meant to say was, if you *fail* to define both __str__ and __repr__,
Python will use whichever you define in place of the missing one.

And of course, if you define neither, then you will inherit from object.



-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list