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'