string 类

Posted chenxiyuxiao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了string 类相关的知识,希望对你有一定的参考价值。

import string

 

string.punctuation   会返回所有常用的标点符号

string.ascii_letters  会返回  a-zA-Z

string.ascii_lowercase  小写a-z

string.ascii_uppercase  大写A-Z

string.digits   字符串 0-9

string.hexdigits   十六进制 数可能涉及到的字母数字大小写

string.whitespace   会返回所有的  空白  包含 换行符 空格  制表符等

 

 

固定的写法搜集 :

  1   s = ‘wrod , hello ! ’           s.translate(str.maketrans(‘‘, ‘‘, string.punctuation))    可实现将字符串的标点符号删除 

以上是关于string 类的主要内容,如果未能解决你的问题,请参考以下文章