[Tutor] Conflicted
Sean 'Shaleh' Perry
shalehperry@attbi.com
Sat, 06 Apr 2002 16:58:59 -0800 (PST)
>
> I am however not quite clear as to why the whole line is being replace
> rather than just the string requested. >
>>> s = 'My name is mud'
>>> s.replace('mud', 'Sean')
'My name is Sean'
>>> s
'My name is mud'
s.replace returns the new string. Keep this mantra in memory at all times when
coding in python -- "A string is a constant, I can not change it". The only
way to change a string is to make a new one.
line = line.replace(x, '') # for instance.