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

Chris Angelico rosuav at gmail.com
Thu Dec 7 15:35:56 EST 2017


On Fri, Dec 8, 2017 at 7:25 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> On 12/7/17 2:41 PM, Ethan Furman wrote:
>>
>> On 12/07/2017 11:23 AM, Ned Batchelder wrote:
>>>
>>> On 12/7/17 1:28 PM, Ethan Furman wrote:
>>
>>
>>>> --> 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.
>>
>>
>> --> a = 'spam'
>> --> a == neds_identity(a)
>> False
>>
>
> Right, but why does one argument return the argument, but n>1 returns a
> tuple of the args?
>

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.

ChrisA



More information about the Python-list mailing list