python之string.maketrans和str.translate
来源:互联网 发布:淘宝碰到专业差评师 编辑:程序博客网 时间:2024/04/24 20:55
转载地址:http://blog.csdn.net/skyin333/article/details/8661131
示例:
doc:
Return a translation table suitable for passing to translate(), that will map each character in from into the character at the same position in to;from and to must have the same length.
Note
Don’t use strings derived from lowercase and uppercase as arguments; in some locales, these don’t have the same length. For case conversions, always usestr.lower() andstr.upper().
Return a copy of the string where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256.
You can use the maketrans() helper function in the string module to create a translation table. For string objects, set the table argument to None for translations that only delete characters:
>>> 'read this short text'.translate(None, 'aeiou')'rd ths shrt txt'
New in version 2.6: Support for a None table argument.
For Unicode objects, the translate() method does not accept the optionaldeletechars argument. Instead, it returns a copy of thes where all characters have been mapped through the given translation table which must be a mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None. Unmapped characters are left untouched. Characters mapped to None are deleted. Note, a more flexible approach is to create a custom character mapping codec using the codecs module (see encodings.cp1251 for an example).
- python之string.maketrans和str.translate
- python之string.maketrans和str.translate
- python string.translate string.maketrans()
- Python中的两个方法string.maketrans()和string.translate()
- string 中的maketrans和translate
- Python——string之maketrans,translate函数
- python中的maketrans和translate
- python中maketrans和translate的用法
- python中maketrans和translate的用法
- Python——maketrans和translate方法
- Python中maketrans和translate方法
- python中maketrans和translate的用法
- Python——maketrans和translate方法
- 轻松python文本专题-maketrans和translate
- python maketrans and translate
- Python——maketrans和translate方法,可以用来从string中替换和删除字符
- Python——maketrans和translate方法,可以用来从string中替换和删除字符
- python 中闭包理解,及函数string.maketrans(),string.translate()
- C#学习日记 表达式树
- B
- HDU 1548:A strange lift
- Java初级笔记-第三章
- 海量数据处理
- python之string.maketrans和str.translate
- Bzoj1901 Zju2112 Dynamic Rankings
- Lua函数库中的常用字符串处理函数详解
- zuoye
- 单例模式有五种写法:懒汉、饿汉、双重检验锁、静态内部类、枚举。
- 紫书章五例题9 数据库 UVA 1592 (map+vector)
- 数据库理论之故障恢复日志
- web.xml is missing and <failOnMissingWebXml> is set to true问题处理
- 矩阵乘法