Help newbie!

Fernando Pérez fperez528 at yahoo.com
Mon Dec 10 10:46:35 EST 2001


Oleg Broytmann wrote:

> On Tue, Dec 11, 2001 at 10:17:35PM +0100, Johan Barelds wrote:
>> >>> replace("hello","hel","hol")
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> NameError: name 'replace' is not defined
>> ========================================================================
>> What do i have to do to get the command "replace" working?
> 
>    Either "from string import replace", or
> 
> import string
> string.replace(...
> 
> Oleg.

No need to import anything:

new_string = 'hello'.replace('hel','hol')

Cheers,

f



More information about the Python-list mailing list