Stackoverflow question: Is there a built-in identity function in Python?
Ben Finney
ben+python at benfinney.id.au
Thu Dec 7 18:38:24 EST 2017
Ethan Furman <ethan at stoneleaf.us> writes:
> 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'
These seem good to me. One argument given, the same result returned.
> --> identity('spam', 'eggs', 7)
> ('spam', 'eggs', 7)
That's a confusingly inconsistent result, as pointed out by other
responses in this thread.
I would expect an identity function to accept exactly one positional
argument. Given more than one positional argument, it should raise a
TypeError.
--
\ Legionnaire: “We have their leader captive!” Cæsar: “Is he |
`\ bound?” Legionnaire: “Of his health I know not, sir.” —The |
_o__) Goon Show, _The Histories Of Pliny The Elder_ |
Ben Finney
More information about the Python-list
mailing list