Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python 3剥离列表中某些字符的字符串_Python 3.x - Fatal编程技术网

Python 3.x Python 3剥离列表中某些字符的字符串

Python 3.x Python 3剥离列表中某些字符的字符串,python-3.x,Python 3.x,如何从列表中的字符中剥离字符串?乙二醇 Striplist = ["+","-","!","*"]; StripString = "A+B*!-+C"; 使用str.translate(): 字符串是列表,所以使用列表理解 字符=[“+”,“-”,“] str=“x+y=1.2” newstr=[c代表str中的c,如果不是字符中的c] 将产生“xy=12”您可以使用replace stripStr.replace(“+”,”).replace(“-”,”).replace(…)的管道。还有其

如何从列表中的字符中剥离字符串?乙二醇

Striplist = ["+","-","!","*"];
StripString = "A+B*!-+C";
使用str.translate():


字符串是列表,所以使用列表理解

字符=[“+”,“-”,“]

str=“x+y=1.2”

newstr=[c代表str中的c,如果不是字符中的c]


将产生“xy=12”

您可以使用replace stripStr.replace(“+”,”).replace(“-”,”).replace(…)的管道。还有其他有效的方法吗?到目前为止,您尝试了哪些方法来解决您的问题?你得到了什么样的产出(你期望得到什么)?虽然一些堆栈溢出用户非常慷慨,即使你的问题非常不完整,他们也可能试图帮助你,但如果你问一个更好的问题,你会得到更多的答案,而且通常会得到更好的答案。有关更多建议,请参阅。@Blckknght指出,下次会问得更好。
>>> tab = str.maketrans('', '', ''.join(["+","-","!","*"]))
>>> "A+B*!-+C".translate(tab)
'ABC'