I have two strings.
dat: "13/08/08
tim: 12:05:51+22"
I want the " character stripped from both the strings. Here is the code I am using:
dat=dat.strip('"')
tim=tim.strip('"')
The resulting strings I get are:
dat: 13/08/08
tim: 12:05:51+22"
Why is the " character not removed from tim?
According to the documentation here ( http://www.tutorialspoint.com/python/string_strip.htm ) it should work.
According to the docs , strip([chars])
:
Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed.
So, "
won't be replaced from dat: "13/08/08
and will be replaced from tim: 12:05:51+22"
because here "
is at the 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'
Seem to work here
>>> tim2 = "tim: 12:05:51+22\""
>>> print tim2
tim: 12:05:51+22"
>>> tim = tim2.strip('"')
>>> print tim
tim: 12:05:51+22
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.