Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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 从字符串中删除特殊字符_Python - Fatal编程技术网

Python 从字符串中删除特殊字符

Python 从字符串中删除特殊字符,python,Python,在下面的字符串中,如何删除所有特殊字符 str1="0Cell Phones: Smartphone,\x02\x05\x0e\x02\x05Mobile Phone - Best Buy13AT&T Wireless: AT&T Phones & Cell Phone Plans - Best Buy4\x02\x05\x0e\x02\x05Cell Phones: Smartphone, Mobile Phone - Best Buy1\x02\x05\x0e\x02

在下面的字符串中,如何删除所有特殊字符

str1="0Cell Phones: Smartphone,\x02\x05\x0e\x02\x05Mobile Phone - Best Buy13AT&T Wireless: AT&T Phones & Cell Phone Plans - Best Buy4\x02\x05\x0e\x02\x05Cell Phones: Smartphone, Mobile Phone - Best Buy1\x02\x05\x0e\x02\x05AT&T Wireless: AT&T Phones & Cell Phone Plans - Best Buy"
使用:

In[35]:str1=“0Cell Phones:Smartphone\x02\x05\x0e\x02\x05手机-百思买13AT&T Wireless:AT&T手机和手机计划-百思买4\x02\x05\x0e\x02\x05手机:智能手机,手机-百思买1\x02\x05\x02\x05AT&T Wireless:AT&T手机和手机计划-百思买”

在[36]:“.join(如果311
可能重复吗?,
\x02
是一个字符,
\x05
也是如此,中间有一个
1
。是的,很好,但是ord(x)代表什么?注意:你可以使用
31
@Rajeev它是一个内置的。你从哪里得到这个列表的?@Rajeev或。
In [35]: str1="0Cell Phones: Smartphone,\x02\x05\x0e\x02\x05Mobile Phone - Best Buy13AT&T Wireless: AT&T Phones & Cell Phone Plans - Best Buy4\x02\x05\x0e\x02\x05Cell Phones: Smartphone, Mobile Phone - Best Buy1\x02\x05\x0e\x02\x05AT&T Wireless: AT&T Phones & Cell Phone Plans - Best Buy"

In [36]: "".join(x for x in str1 if 31 < ord(x) <127)

Out[36]: '0Cell Phones: Smartphone,Mobile Phone - Best Buy13AT&T Wireless: AT&T Phones & Cell Phone Plans - Best Buy4Cell Phones: Smartphone, Mobile Phone - Best Buy1AT&T Wireless: AT&T Phones & Cell Phone Plans - Best Buy'