re: Python Lambda Functions - What The? VIEW POST

FULL DISCUSSION
 

Not possible to provide a docstring

It is possible with the __doc__ variable. But if you want to do that you are IMO better of defining a function the standard way.


def test_stuff(a):
    """some doc string"""
    return a

print(test_stuff.__doc__)
# => 'some doc string'

test_other_stuff = lambda x: x
test_other_stuff.__doc__ = 'some other doc string'
print(test_other_stuff.__doc__)
# => 'some other doc string'
 

That is certainly one approach. Though as you highlighted it would definitely be better to just use a standard function if you had to provide a docstring.

code of conduct - report abuse