Top and Bottom Values [PEP: 326]

John Machin sjmachin at lexicon.net
Wed Sep 27 05:15:07 EDT 2006


Lawrence D'Oliveiro wrote:
> In message <slrnehk7ju.rcu.apardon at rcpc42.vub.ac.be>, Antoon Pardon wrote:
>
> > I need this Top value in
> > a context where it can be used as a start or stop value
> > in a slice.
>
> But the only valid values allowed for indices are 0 up to the length of the
> array inclusive. Larger integers are not allowed, so why should Top be
> allowed?

Larger integers are not allowed as subscripts, but slicing is more
tolerant:

| >>> array = ['a', 'b', 'c']
| >>> array[:1]
| ['a']
| >>> array[:2]
| ['a', 'b']
| >>> array[:3]
| ['a', 'b', 'c']
| >>> array[:4]
| ['a', 'b', 'c']
| >>> array[:987654321]
| ['a', 'b', 'c']

BTW, negative subscripts are allowed, too; see e.g.
http://docs.python.org/tut/node5.html#SECTION005140000000000000000

HTH,
John




More information about the Python-list mailing list