Bug or feature?
Remco Gerlich
scarblac at pino.selwerd.nl
Wed Mar 21 07:38:15 EST 2001
Markus Reitz <Markus_Reitz at yahoo.com> wrote in comp.lang.python:
> Hi,
>
> I'm using Python 2.0 and have found a, according to my opinion, strange
> behaviour.
>
> a=[]
> a.extend('Test')
>
> Printing a results in:
>
> a=['T','e','s','t']
>
> I expected a TypeError message, because a String is not a list and so it
> can't be used to extend an existing list.
>
> On the other hand, a string can be seen as a kind of "list of characters"
> ...
>
> Is this behaviour a bug or a feature?
Feature. Strings are sequences, just like lists, tuples and any class
instances with the right methods (__getitem__, mostly).
>>> for a in "whee": print a
w
h
e
e
>>> list("whee")
['w','h','e','e']
--
Remco Gerlich
More information about the Python-list
mailing list