List problem
Fredrik Lundh
fredrik at pythonware.com
Thu Aug 24 18:38:02 EDT 2006
kevndcks at aol.com wrote:
> For example i write the following code in the Python command line;
>
>>>> list = ['One,Two,Three,Four']
>
> Then enter this command, which will then return the following;
>
> ['One,Two,Three,Four']
>
>
> Now the problem, reading through the Python tutorial's, it describe's
> that list's can sliced, concatenated and so on etc
>
> So i write the following
>
>>>> list[1:] + ['Five']
>
> Then the error returned is that 'str' and 'list' could not be
> concatenated which is where it baffles me.
if you got that error, you clearly didn't type what you say you typed:
>>> list = ['One,Two,Three,Four']
>>> list
['One,Two,Three,Four']
>>> list[1:] + ['Five']
['Five']
(note that the first list contains a single string; if you want to put
multiple strings in a list, you need to be more careful with where you
put the quotes.)
</F>
More information about the Python-list
mailing list