python使用string去掉字符串末尾的标点符号

处理要求:去掉2.0.1.中最右侧的标点符号
导入string模块,处理过程如下:

In [101]: import string       
In [102]: a = '2.0.1.'                                                                                                      
In [103]: a                                                                                                                 
Out[103]: '2.0.1.'
In [104]: a = a.strip(string.punctuation)                                                                                   
In [105]: a                                                                                                                 
Out[105]: '2.0.1'

猜你喜欢

转载自blog.51cto.com/maoxiaoxiong/2331566