Removing a character from a string in Python using strip() -
i have 2 strings.
dat: "13/08/08 tim: 12:05:51+22" i want " character stripped both strings. here code using:
dat=dat.strip('"') tim=tim.strip('"') the resulting strings are:
dat: 13/08/08 tim: 12:05:51+22" why " character not removed tim?
according documentation here (http://www.tutorialspoint.com/python/string_strip.htm) should work.
according docs, strip([chars]):
return copy of string leading , trailing characters removed. chars argument string specifying set of characters removed.
so, " won't replaced dat: "13/08/08 , replaced tim: 12:05:51+22" because here " @ end:
>>> dat = 'dat: "13/08/08' >>> tim = 'tim: 12:05:51+22"' >>> dat.strip('"') 'dat: "13/08/08' >>> tim.strip('"') 'tim: 12:05:51+22' use replace() instead:
>>> dat.replace('"', '') 'dat: 13/08/08' >>> tim.replace('"', '') 'tim: 12:05:51+22'
Comments
Post a Comment