String模块中的常量

>>> import string
>>> string.digits
''
>>> string.letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> string.lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
>>> string.uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>>
#String.capwords(S)它把S用split()函数分开,然后用
#capitalize()把首字母变成大写,最后用join()合并到一起 >>> s
'* python * * string *'
>>> string.capwords(s)
'* Python * * String *'

Python maketrans() 方法用于创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标。

注:两个字符串的长度必须相同,为一一对应的关系。

from string import maketrans   # 必须调用 maketrans 函数。

intab = "aeiou"
outtab = ""
trantab = maketrans(intab, outtab) str = "this is string example....wow!!!";
print str.translate(trantab);

Python translate() 方法根据参数table给出的表(包含 256 个字符)转换字符串的字符, 要过滤掉的字符放到 del 参数中。

str.translate(table[, deletechars]);
table -- 翻译表,翻译表是通过maketrans方法转换而来.
deletechars -- 字符串中要过滤的字符列表
from string import maketrans   # 引用 maketrans 函数。

intab = "aeiou"
outtab = ""
trantab = maketrans(intab, outtab) str = "this is string example....wow!!!";
print str.translate(trantab); th3s 3s str3ng 2x1mpl2....w4w!!! print str.translate(trantab, 'xm'); th3s 3s str3ng 21pl2....w4w!!!

python string module的更多相关文章

  1. python string

    string比较连接 >>> s1="python string" >>> len(s) 13 >>> s2=" p ...

  2. The internals of Python string interning

    JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A fe ...

  3. python模块module package

    python模块module   package module package 常用模块 模块与包的区别 模块分为内置模块.第三方模块,自定义模块 程序会先从内置到第三方再到当前工作目录下去找你导入的 ...

  4. Python string interning原理

    原文链接:The internals of Python string interning 由于本人能力有限,如有翻译出错的,望指明. 这篇文章是讲Python string interning是如何 ...

  5. Requests:Python HTTP Module学习笔记(一)(转)

    Requests:Python HTTP Module学习笔记(一) 在学习用python写爬虫的时候用到了Requests这个Http网络库,这个库简单好用并且功能强大,完全可以代替python的标 ...

  6. Python string objects implementation

    http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects impleme ...

  7. Python string replace 方法

    Python string replace   方法 方法1: >>> a='...fuck...the....world............' >>> b=a ...

  8. python no module named _socket 原因

    python no module named _socket 原因 Lib/site-packages 不在 sys.path 中

  9. Python “No module named” 以及在Python2中可以导入,但在python3中却出现的原因

    Python “No module named” 以及在Python2中可以导入,但在python3中却出现的原因 原因之1: 例如有这样的一个包和它的模块: Test __init__.py Mod ...

随机推荐

  1. windows目录选择 文件选择 文件保存对话框

    打开文件对话框 const char pszFilter[] = _T("EXE File (*.txt)|*.txt|All Files (*.*)|*.*||"); CFile ...

  2. 【xsy1230】树

    题意 \(N\)个点的树,边有边权.给\(M\)个询问,每个询问包含3个参数\(l,r,pos\),求标号在\(l\)到\(r\)中的所有点中,离节点pos最近的点到pos的距离. 分析:动态点分治+ ...

  3. CSS权重及样式优先级问题

    CSS权重值计算 一条样式规则的整体权重值包含四个独立的部分:[A, B, C, D]; (1) A 表示内联样式(写在标签的style属性中),只有 1 或者 0 两个值:对于内联样式,由于没有选择 ...

  4. OLE填充EXCEL 多SHEET

    "1 设置行高 "参数说明:行/列号.行高/列宽.R-行 C-列 FORM row_column USING p_r p_width p_type. CASE p_type. WH ...

  5. Oracle 字符串分割排序冒泡算法

    例子: 一个字符串"11,15,13,17,12",以逗号分割,现在要排序成"11,12,13,15,17". 写了一个实现方法,记录下来以备后用: ----- ...

  6. IOS开发UI篇—导航控制器属性和基本使用

    IOS开发UI篇—导航控制器属性和基本使用 一.导航控制器的一些属性和基本使用 1.把子控制器添加到导航控制器中的四种方法 (1) 1.创建一个导航控制器 UINavigationController ...

  7. 32个触发事件XSS语句的总结

    1.onmouseenter:当鼠标进入选区执行代码 <div style="background-color:red" onmouseenter="alert(b ...

  8. Leetcode 155 Min Stack 小顶堆+栈,优先队列实现 难度:0

    https://leetcode.com/problems/min-stack/ #include <vector> #include <queue> #include < ...

  9. Rhel6-varnish配置文档

    系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.160:virnish apache server60.example ...

  10. iOS系统消息

    一.键盘1.UIKeyboardWillShowNotification-将要弹出键盘2.UIKeyboardDidShowNotification-显示键盘3.UIKeyboardWillHideN ...