【python】 string.puntuation符号匹配原则

来源:互联网 发布:模拟电路软件汉化版 编辑:程序博客网 时间:2024/05/18 22:18

由于在使用的时候发现字符串中有些标点被比配,有些则没有被匹配,搜了一下没有找到具体解释,下面就发一些自己测试的结果仅供参考。

#!usr/bin/env python#-*-coding:utf-8-*-import stringimport restring1='(3.6.3)fadssa.7/4.'string2='hello/2017-19-29...//'string3='hello./.,;'print(string1.strip(string.punctuation))print(string2.strip(string.punctuation))print(string3.strip(string.punctuation))
输出结果如下:

(3.6.3fadssa.7/4hello/2017-19-29hello


特别注意一下string1中7前的点被当作小数点不会消除而4后的点会被消除,3.6.3之前(不被消除,之后的被消除。所以可以解释为,放在数字之前的符号不会被匹配到。




原创粉丝点击