Python's `help()` in other languages.
Frederik 👨💻➡️🌐 Creemers Aug 10
In Python's interactive interpreter, I can do thiq:
And it'll pop up a help page like this:
Help on built-in function reduce in module __builtin__: reduce(...) reduce(function, sequence[, initial]) -> value Apply a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). If initial is present, it is placed before the items of the sequence in the calculation, and serves as a default when the sequence is empty.
I can do this for non built-in functions as well. A triple-quoted string at the start of the function body defines a "docstring".
>>> def handshakes(n): ... """Returns the number o handshakess that occur in a group of n people if everyone shakes everyone's hand.""" ... return (n*(n-1))/2 ... >>> help(handshakes)
I get this help page:
Help on function handshakes in module __main__: handshakes(n) Returns the number o handshakes that occur in a group of n people if everyone shakes everyone's hand.