Pythonchallenge learned Python built-in function collation

Source: Internet
Author: User

No. 0 Pass:

Computes the n-th side of x: X**n

First Pass:

Maketrans (from,to): Set up a translation rule that translates the from translation to A to, because the lengths of the two parameters must be the same

Translate (Table[,deletechars]): Translation of a string using the translation rules above

Example

1 # -*-coding:utf-8-*- 2 Import string 3 3 table = String.maketrans ('a'b')  4print'make'. Translate (table)

Second Pass:

The Python Isalpha () method detects whether a string consists of only letters.

# -*-coding:utf-8-*- # cannot have spaces in a string " Helloword " ;   Print  "Hello Word"; print str.isalpha ();

Third Pass:

The general step for using RE is to use the Re.compile () function, compile the string form of the regular expression into a pattern instance, then use the pattern instance to process the text and get the matching result (a match instance), and finally use the match instance to get the information. To do other things.

re. Match(pattern, string, flags=0) :p attern-> matching Regular expression;string-> the string;flags-> flag bits to match to control how regular expressions are matched, such as: case-sensitive, Multi-line matching and so on.

Re.findall (b): Find all the locations in string B that match regular expression A and put them in a list;

1 Re.complie (a) 2 3 a.findall (b)

Re module is one of the most commonly used Python modules, there are many tutorials on the web, no longer repeat here, you can go to the novice tutorial to see.

Four-off:

Review re module, introduce Urllib, about Urllib module, will be detailed later

# ==========================================================================

Cracked to the four has been tired. Good programming ability low, need to improve
, go to work for two days and then play.

-----Python Pupils

Pythonchallenge learned Python built-in function collation

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.