Why these don't work??

M. Hamed mohammed.elshoukry at microchip.com
Thu Apr 8 16:08:16 EDT 2010

Thanks All. That clears alot of confusion. It seems I assumed that
everything that works for lists works for strings (the immutable vs
mutable hasn't sunken in yet).

On the other hand (other than installing NumPy) is there a built-in
way to do an array full of zeros or one just like the numpy.zeros()? I
know I can do it with list comprehension (like [0 for i in
range(0,20)] but these are too many keystrokes for python :) I was
wondering if there is a simpler way.

I had another question about arrays but I should probably start
another thread.


On Apr 8, 11:43 am, MRAB <pyt... at mrabarnett.plus.com> wrote:
> M. Hamed wrote:
> > I'm trying the following statements that I found here and there on
> > Google, but none of them works on my Python 2.5, are they too old? or
> > newer?
> > "abc".reverse()
> Lists have a .reverse() method which reverses the list elements
> in-place, but strings don't because they're immutable.
> There's a built-in function reversed() which returns an iterator over an
> iterable object, eg a string:
>      print reversed("abc")
>      for c in reversed("abc"):
>          print c
> It's all in the documentation.
> > import numpy
> numpy isn't part of the standard library; you'd need to download and
> install it.

More information about the Python-list mailing list