Entry
How can I strip unwanted characters out of my string? Octal 240 for instance.
Dec 18th, 2009 15:23
new acct, unknown unknown, Ken Seehof
>>> "s\240p\240a\240m".replace("\240","")
'spam'
But I want to actually strip them out of my string:
Can't exactly do that. Strings are immutable. If you don't know what
I mean by immutable, find out (mutability is a key concept of python).
(Hint: if strings were not immutable, they could not be safely used as
keys in dictionaries.)
So you'll have to settle for:
>>> s = "s\240p\240a\240m"
>>> s = s.replace("\240", "")
>>> print s
spam