Since I am new to programming, I just want to understand the format the built-in functions is represented in the documentations. This is the one from python
bytearray ([source[, encoding[,errors]]])
Why all the square brackets are terminated at the end? The brackets are nested. There is comma immediately after the square bracket too. Does it mean it takes only 3 arguments? Is the below same as the above one?
bytearray ([source],[encoding],[errors])
I am not understanding the format it represents.
2
Brackets means something is optional. For instance foo[bar]qux
could be either fooqux
or foobarqux
. You could treat it like a regular expression foo(bar)?qux
in your head if that helps.
Thus bytearray ([source[, encoding[,errors]]])
could be any one of
bytearray(source, encoding, errors)
bytearray(source, encoding)
bytearray(source)
bytearray()
This also shows that you need to open the brackets before the comma, and close them all at once. With your suggested bytearray([source], [encoding], [errors])
, the options would be:
bytearray(source, encoding, errors)
bytearray(source, , )
bytearray(, , errors)
bytearray(, , )
- etc. (There are eight possibilities in total, I’m not going to type them all out.)