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. 常用sql语句总结

    一.连接数据库 mysql -h127.0.0.1(连接地址) -P3303(端口号) -uroot(用户名) -p123456(密码) 二.常用语句 show datebases; 查看数据库 cr ...

  2. 鼠标滑过弹出jquery在线客服

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. js时间格式转换的几种方法

    公司项目需要获取时间并且转换格式,之前没有实现过但读过源码,新来的小哥给我讲了下细节.算是学到了..... function getLocalTime(){ var now=new Date(); v ...

  4. Object.create()兼容实现方法

    if (!Object.create) { Object.create = (function(){ function F(){} return function(o){ if (arguments. ...

  5. HTML 段落<p>标签

    <p> 标签定义段落. p 元素会自动在其前后创建一些空白.浏览器会自动添加这些空间,您也可以在样式表中规定. 段间距IE默认为19px,通过p的margin-top属性设置FF默认为1. ...

  6. jfinal 基本应用 --定时任务 QuartzPlugin

    jfinal 的定时器的使用: 项目中使用的maven管理器 1.导入要使用的包 2.添加Job类 配置参数 这个配置是jfinal-quartz 包中带的默认文档,即是默认加载的文档(其中还有一个q ...

  7. iOS开发UI篇—推荐两个好用的Xcode插件(提供下载链接)

    iOS开发UI篇—推荐两个好用的Xcode插件(提供下载链接) 这里推荐两款好用的Xcode插件,并提供下载链接. 一.插件和使用如下: 1.两款插件 对项目中图片提供自动提示功能的插件:KSImag ...

  8. 用python定时文章发布wordpress

    用python定时文章发布wordpress: 流程: 采集 - 筛选文章 - wordpress文章发布. wordpress文章发布代码:python利用模块xmlrpclib发布文章非常便捷,省 ...

  9. 一个null引发的错误

    写程序时,发生一个unrecognized selector的错误,很显然,这是一个经典错误,运行时找不到可调用的方法. 系统提示的reason是 -[NSNull length] 错误 经过查找,原 ...

  10. 《final修饰基本类型变量和引用类型变量的区别》

    //final修饰基本类型变量和引用类型变量的区别 import java.util.Arrays; class Person { private int age; public Person(){} ...