What is the meaning of the square brackets inside the round brackets of a function in the Python documentation?
E.g.:
help([object])
or
int([x[, base]])
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.
The indexing operator (Python uses square brackets to enclose the index) selects a single character from a string. The characters are accessed by their position or index value. For example, in the string shown below, the 14 characters are indexed left to right from postion 0 to position 13.
Indexing DataFrames You can either use a single bracket or a double bracket. The single bracket will output a Pandas Series, while a double bracket will output a Pandas DataFrame.
Alternative is to press keys with shift u til you find the ones with square brackets.
Everything that is in square brackets is optional, i.e. you can omit it. If the square brackets contain more than 1 argument, you can't choose which ones to omit, you must either specify all of them, or none.
That's where nested brackets come in handy:
int([x[, base]])
Here, for example, you can use int() without arguments (by omitting the whole outer bracket) or int(x) (by omitting the inner bracket) or int(x, base). But not int(base) (well, that would just mean int(x)).
This isn't actual Python syntax, just a way for documentation to be clearer. Python 3's documentation tries to avoid these brackets.
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