Python-Abbreviation (capwords) and create conversion table (Maketrans) Detailed description

Source: Internet
Author: User
Tags comparison table

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.