Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I read the Python documentation a lot and sometimes I am baffled by this notation:

os.path.join(path1[, path2[, ...]])

I somehow make that [, path[,...]] is a list but I would like to know if I am reading it correctly.

Bear with me, this is coming from a Java developer who is trying out Python. X)

share|improve this question
If you ever encountered BNF notation, you remember that it puts optional parts into [square brackets]. – 9000 Jan 24 '11 at 17:47
What does BNF use for literal square brackets? – dan04 Jan 25 '11 at 6:08
up vote 7 down vote accepted

That is for multiple arguments. You could call that method with 1 or more variables. That particular method could be called with:

  1. join(path1)
  2. join(path1, path2)
  3. join(path1, path2, <optional parameters>)

Option 3 can only be used when the path2 argument is present. If you have have use C, think printf("Number %d", number);

According to the python documentation, those optional parameters are for more paths. So you could call join(path1, path2, path3, path4) or with as many paths as you like.

share|improve this answer
It should be "with one or more". +1 for all else. – Jon Purdy Jan 24 '11 at 17:33
@Jon: Thanks for edit! – Michael K Jan 24 '11 at 17:34
But can the parameters be passed, say, in one list? – Jeune Jan 24 '11 at 19:33
@Jeune: I don't think so, but I'm not a python expert by any strech. – Michael K Jan 25 '11 at 2:35
@Jeune: you can use *args, to unpack a list as arguments to a function. ie os.path(*[arg1, arg2, arg3]), or if args was already a list. – Matthew Schinckel Jan 26 '11 at 7:39

The brackets indicate an optional parameter. The ellipses indicate a variable-length argument list.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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