s.index(x[, i[, j]]) will change the s ?

r rt8396 at gmail.com
Thu Sep 10 00:19:09 EDT 2009


On Sep 9, 11:00 pm, s7v7nislands <s7v7nisla... at gmail.com> wrote:
> hi all:
>     what is the s.index() mean? does the index() change the s?
>     In python2.6 doc (6.6.4. Mutable Sequence Types), Note 4:
>> Raises ValueError when x is not found in s. When a negative index is
> passed as the second or third parameter to the index() method, the
> list length is added, as for slice indices. If it is still negative,
> it is truncated to zero, as for slice indices.
>> Changed in version 2.3: Previously, index() didn’t have arguments for
> specifying start and stop positions.
>> who can give a example?  and why the s.remove() also point to note 4?
> Is the document wrong?

the Python command line is your buddy and the IDLE shell is your BFF.
>>> s = 'abcdefg'
>>> s.index('a')
0
>>> s.index('b')
1
>>> s.index('g')
6
>>> len(s)
7
>>> s
'abcdefg'
Python strings are immutable!
http://en.wikipedia.org/wiki/Immutable_object
try this command
>>> help(str)

--
def get_enlightened():
 import webbrowser
 webbrowser.open('http://jjsenlightenments.blogspot.com/')


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /