How to detect that a function argument is the default one

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 10 11:20:48 EST 2014


On Wed, Dec 10, 2014 at 9:10 AM, Jean-Michel Pichavant <
jeanmichel at sequans.com> wrote:
> If you like one-liners,
>
> def __init__(self, center=(0,0), radius=10, mass=None):
>     self.center = center
>     self.radius = radius
>     self.mass = (mass is None and radius**2) or mass

If mass is None and radius is 0, then self.mass gets set to None. Use the
actual ternary operator instead.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141210/0a018c1b/attachment.html>


More information about the Python-list mailing list