Clarification of notation

Terry Reedy tjreedy at udel.edu
Thu Sep 30 00:55:59 EDT 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 
example.
 >>> 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.
https://secure.wikimedia.org/wikipedia/en/wiki/Backus%E2%80%93Naur_Form

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