python string module
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的更多相关文章
- python string
string比较连接 >>> s1="python string" >>> len(s) 13 >>> s2=" p ...
- The internals of Python string interning
JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A fe ...
- python模块module package
python模块module package module package 常用模块 模块与包的区别 模块分为内置模块.第三方模块,自定义模块 程序会先从内置到第三方再到当前工作目录下去找你导入的 ...
- Python string interning原理
原文链接:The internals of Python string interning 由于本人能力有限,如有翻译出错的,望指明. 这篇文章是讲Python string interning是如何 ...
- Requests:Python HTTP Module学习笔记(一)(转)
Requests:Python HTTP Module学习笔记(一) 在学习用python写爬虫的时候用到了Requests这个Http网络库,这个库简单好用并且功能强大,完全可以代替python的标 ...
- Python string objects implementation
http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects impleme ...
- Python string replace 方法
Python string replace 方法 方法1: >>> a='...fuck...the....world............' >>> b=a ...
- python no module named _socket 原因
python no module named _socket 原因 Lib/site-packages 不在 sys.path 中
- Python “No module named” 以及在Python2中可以导入,但在python3中却出现的原因
Python “No module named” 以及在Python2中可以导入,但在python3中却出现的原因 原因之1: 例如有这样的一个包和它的模块: Test __init__.py Mod ...
随机推荐
- SSH2 框架下的分页
1.设计分页实体(pageBean) 这里我显示的是3-12页的方式: package cn.itcast.oa.domain; import java.util.List; /** * 封装分页信息 ...
- 数据库 基础篇3(mysql语法)
4 数据库管理(接上篇) 4.1 查询所有数据库 mysql> show databases; +--------------------+ | Database | +-- ...
- 【转】关于 Web GIS
以下部分选自2015-03-01出版的<Web GIS从基础到开发实践(基于ArcGIS API for JavaScript)>一书中的前言部分: Web GIS 概念于1994 年首次 ...
- 线性表(一)——数组循环右移算法
源码:rshift.cpp #include "stdafx.h" #include <stdio.h> /****************************** ...
- angular directive指令内的参数
angular.module('myApp', []) .directive('myDirective', function() { return { restrict: String, priori ...
- Launch Screen在iOS7/8中的实现
Launch Screen在iOS7/8中的实现 目前项目中需要解决的问题是: 兼容iOS7和iOS8,之前的版本不需要支持了 实现兼容3.5.4.4.7和5.5寸屏幕,竖屏的Lauch Screen ...
- [转]Android,Yocto,Meego构建系统的区别
http://m.blog.csdn.net/blog/sonach_tjsd/6647829
- 排序小结(java版)
一.归并排序 package org.lxh.demo08.b; class Sort { private int[] a; private int n; Sort(int n) { a=new in ...
- tinymce 编辑器 上传图片
tinymce编辑器进行本地图片上传 首先下载tinymce.js之后 在form中添加一个<textarea>元素 给其一个id和name 然后就可以初始化编辑器了 tinymce.in ...
- css3 弹框提示样式
.common-dialog-box{ opacity: 0; filter: alpha(opacity=0); position: fixed; top: 0%; left: 50%; z-ind ...