python strip怎样去引号

如题所述

python 字符串中的strip方法只能在首尾去除参数中指定的字符,不传参数默认是去除首尾的空白符

' head tail '.strip()#去除首尾空白符
' "head tail "'.strip('"')#去除双引号

如果要去除所有的引号,得用字符串的replace方法

' head tail '.replace(' ','')#去除所有空白符
'"head" and "tail"'.replace('"','')#去除所有的双引号

温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2018-03-02

要加转义

>>> a="\"abc\""

>>> print a

"abc"

>>> print a.strip("\"")

abc

本回答被网友采纳
相似回答