Clarification of notation

Terry Reedy tjreedy at
Thu Sep 30 06:55:59 CEST 2010

On 9/29/2010 10:32 PM, Bruce Whealton wrote:

> Would you, and could you combine a dictionary with a list in this fashion?

A python list is a mutable sequence of Python objects. Extremely mixed 
 >>> mixed = [1, 1.0, '1', [1], (1,), {1:1}, set((1,)), list, list.append]
 >>> mixed.append(mixed) # make the list recursive
 >>> mixed # list to string can handle that!
[1, 1.0, '1', [1], (1,), {1: 1}, {1}, <class 'list'>, <method 'append' 
of 'list' objects>, [...]]

> Next, from the documentation I see and this is just an example (this
> kind of notation is seen elsewhere in the documentation:
> str.count(sub[, start[, end]])

square bracket are standard for indicating optional items in extended 
Backus-Naur context-free grammar notations.

In Python3 docs, they have been removed as redundant when an explicit 
default value is given:
compile(source, filename, mode, flags=0, dont_inherit=False)

Terry Jan Reedy

More information about the Python-list mailing list