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

Ned Batchelder ned at nedbatchelder.com
Thu Dec 7 15:25:45 EST 2017


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?

--Ned.



More information about the Python-list mailing list