Stackoverflow question: Is there a built-in identity function in Python?

Paul Moore p.f.moore at gmail.com
Thu Dec 7 17:18:40 EST 2017


On 7 December 2017 at 20:35, Chris Angelico <rosuav at gmail.com> wrote:
> Because it's impossible to return multiple values. IMO the "identity
> function" is defined only in terms of one single argument, so all of
> this is meaningless.

Indeed, this is the key point. The Python language only allows
returning one value (which can be a tuple, sure, but it's still *one
value*). So a function that returns what it's called with can only
have one argument.

Anything else isn't an "identity function". Certainly, it might be
useful - "def f(arg, *rest, **kw): return arg" could be a useful dummy
function in some contexts, for example - but it's not an identity
function in the strict sense (and so you can't avoid having to specify
its behaviour explicitly).

Paul



More information about the Python-list mailing list