Often when reading documentation on what arguments can be passed to a method, I see brackets used within the arguments list like this:
What do the brackets mean in this context? Why are the commas inside the brackets?
Square brackets indicate optional parts of a statement. They should not be entered. In many cases, items in the square brackets are optional because default values are provided. | A vertical bar indicates a choice between two or more items or values, usually within square brackets or curly braces.
Almost all functions require arguments enclosed in parentheses and separated by commas. If arguments are required, do not place any spaces between the function name and the left parenthesis. Syntax rules must be followed.
The square brackets tell Python that this is a list comprehension, producing a list. If you use curly braces, you'll get either a set or a dict back, and if you use regular parentheses, you'll get a generator expression (see above).
The square brackets indicate that these arguments are optional. You can leave them out.
required
[optional]
<required>
[<optional>, <but both needed>]
.
This is almost always the case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With