[docs] Typo in the String docs

Sandro Tosi sandro.tosi at gmail.com
Tue Aug 14 13:49:43 CEST 2012


Hello Ramon,

On Mon, Aug 13, 2012 at 2:09 PM, Ramon Royo Giner <rroyog at uoc.edu> wrote:
> "Helloo".replace('oo', 'o') #does work -> "Hello"
> "Helloo".replace('Helloo', 'oo', 'o') #doesnt work, throws a type error,
> because 'o' is in the place of the third argument (maxreplace), which should
> be an int

I'm sorry, I could have used some examples to make my original email
more clear. What you're doing is using the replace() method of the
string object:

>>> s = "Helloo"
>>> type(s)
<type 'str'>

which has the first argument already "filled":

>>> s.replace('oo', 'o')
'Hello'

so you don't need to specify once again the string it operates on. In
the example you cited in the original email refers to the replace()
function of the string module:

>>> import string
>>> string.replace('Helloo', 'oo', 'o')
'Hello'

Regards,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi


More information about the docs mailing list