参考以下:
In [20]: aa=u\\'kasdfjskdf12334342\\'
In [21]: filter(str.isdigit,str(aa))
Out[21]: \\'12334342\\'
In [22]: filter(str.isalpha,str(aa))
Out[22]: \\'kasdfjskdf\\'
注意,这个因为要用到 str 函数,所以如果字符串中有非 ascii 码(如汉字)会报错。
要先去掉非 ascii 码字符再用上面的方法。
温馨提示:答案为网友推荐,仅供参考