When using Python's help function, have you ever wondered what the various symbols (/, *, [, and ]) mean? Understanding those symbols will help you better understand how to use the functions and classes you're working with.
Table of contents
- What do all the symbols mean in help output?
- Multiple function signatures
- Pay attention to the nouns
- The symbols of help
- Default values: the
=symbol - Unlimited arguments: the
*symbol before an argument name - Keyword-only arguments: a lone
*symbol - Positional-only arguments: a lone
/symbol - Arbitrary keyword arguments: the
**symbol - Square brackets: optional arguments
- Ellipsis (
...) and other weird things - The conventions of Python's
helpfunction
What do all the symbols mean in help output?
We'll cover what the * and / symbols below mean:
>>> help(sorted)Help on built-in function sorted in module builtins:sorted(iterable, /, *, key=None, reverse=False) Return a new list containing all items from the iterable in ascending order. A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order.We'll also talk about the different formats that help output comes in.
For example, note the square brackets in [x] below and note that there are two different styles noted for calling int:
>>> help(int)Help on class int in module builtins:class int(object) | int([x]) -> integer | int(x, base=10) -> integerWe'll start by giving a name to that line which indicates how a function, method, or class is called.
Multiple function signatures
A function signature notes the …