Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int([x[, base]]). Square brackets in functions in Python documentation? [duplicate]

Tags:

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]])

like image 923
Bentley4 Avatar asked Apr 07 '12 09:04

Bentley4


People also ask

What does square brackets mean in documentation?

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.

What is the function of square bracket in Python?

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.

What does 2 square brackets mean in Python?

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.

How do you write square brackets in Python?

Alternative is to press keys with shift u til you find the ones with square brackets.


1 Answers

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.

like image 159
Oleh Prypin Avatar answered Jan 03 '23 00:01

Oleh Prypin