python去掉字符串中某些特定的字符

1 . 去掉一行字符串中的汉字

english_only = ''.join(x for x in str(col) if ord(x) < 256)

2. 去掉字符串中所有的英文以及一些特殊符号

#re是一个python库,需要提前倒入这个库
str = re.sub("[A-Za-z0-9\!\%\[\]\,\。\.]", "", col)

猜你喜欢

转载自blog.csdn.net/liushao123456789/article/details/79669369