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.

  • Stuff being in square brackets means it's optional. It being nested means it's optional, but the outer levels of nesting must be there if it is.
    – TZHX
    Feb 25, 2017 at 15:11
  • 1
    Cross-site dupe: stackoverflow.com/questions/1718903/…. Please research before asking.
    – jonrsharpe
    Feb 25, 2017 at 16:47

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.