Stackoverflow question: Is there a built-in identity function in Python?
Ned Batchelder
ned at nedbatchelder.com
Thu Dec 7 14:23:21 EST 2017
On 12/7/17 1:28 PM, Ethan Furman wrote:
> The simple answer is No, and all the answers agree on that point.
>
> It does beg the question of what an identity function is, though.
>
> My contention is that an identity function is a do-nothing function
> that simply returns what it was given:
>
> --> identity(1)
> 1
>
> --> identity('spam')
> 'spam'
>
> --> identity('spam', 'eggs', 7)
> ('spam', 'eggs', 7)
I don't see why this last case should hold. Why does the function take
more than one argument? And if it does, then why doesn't it work like this?
--> identity('spam')
('spam',)
(because then it wouldn't be an identity function!) Trying to handle
the multi-argument case seems like it adds an unneeded special case to
the function.
--Ned.
More information about the Python-list
mailing list