slicing, mapping types, ellipsis etc.
Caleb Hattingh
caleb1 at telkomsa.net
Mon Nov 29 23:20:25 EST 2004
I'm going to assume the following is self-explanatory - type the commands
in yourself.
'>>> a = 'hello my name is caleb'
'>>> b = a.split()
'>>> b
['hello', 'my', 'name', 'is', 'caleb']
'>>> b[0]
'hello'
'>>> b[1]
'my'
'>>> b[0:1]
['hello']
'>>> b[0:2]
['hello', 'my']
'>>> b[-1]
'caleb'
'>>> b[:-2]
['hello', 'my', 'name']
'>>> b[2:-2]
['name']
'>>>
thx
Caleb
On 29 Nov 2004 15:49:30 -0500, Jerry Sievers <jerry at jerrysievers.com>
wrote:
>
> Slice objects
> Slice objects are used to represent slices when
> extended
> slice syntax is used. This is a slice using two colons, or
> multiple
> slices or ellipses separated by commas, e.g., a[i:j:step],
> a[i:j,
> k:l], or a[..., i:j]. They are also created by the built-in
> slice()
> function.
>
> A quick example on how this is used and/or pointer to more reading is
> greatly appreciated.
>
> Thanks
>
>
More information about the Python-list
mailing list