abbreviation (capwords) and create conversion table (Maketrans) detailed description
This address: http://blog.csdn.net/caroline_wendy/article/details/27051977
A string module that includes constants and classes that handle text.
capwords (), capitalize the first letter of all the words in the string (string);
Maketrans (), create a comparison table, and then use the translate () function, invoke the comparison table, and replace the characters in the string with the corresponding substitution.
Code:
#-*-Coding:utf-8-*-"Created on 2014.5.26@author:c.l.wang" ' Import strings = ' The quick brown fox jumped over the LA Zy dog. ' Leet = String.maketrans (' ABCDEFG ', ' 1234567 ') #leet brain remnant if __name__ = = ' __main__ ': print (s) print ( String.capwords (s)) #首字母大写 print (S.translate (leet)) #转换 Pass
Output:
The quick brown fox jumped over the lazy dog. The Quick Brown Fox Jumped over the Lazy dog.th5 qui3k 2rown 6ox jump54 ov5r th5 l1zy 4o7.
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Python-Abbreviation (capwords) and create conversion table (Maketrans) Detailed description