Python Learning Notes

Source: Internet
Author: User

1,  beautifulsoup is a useful python-written html/xml parser that can handle nonstandard tags and generate a parse tree. BeautifulSoup can manipulate the note object.
Tag (corresponding to the label in HTML)
Tag.attrs (all properties of the tag are returned as a dictionary)
You can add, delete, and change the properties of the tag directly.

2, python regular expression results, Re.search.group () is used to extract the string that is intercepted by the packet match, () the number within the () is used to denote the grouping
1) group () is the same group (0) that matches the regular expression overall result
     Group (1) lists the first brace matching part, Group (2) lists the second bracket matching part, Group (3) lists the third bracket matching part, and so on;
2.) No match succeeded, Re.search () returns none;
3.) There are no parentheses in the regular expression, and group (1) has an error.

3, The difference between Re.match and Re.search: Re.match matches only the beginning of the string, if the string starts not conforming to the regular expression, the match fails, the function returns none, and the Re.search matches the entire string until a match is found; Re.sub is used to replace the match in the string;

4, l Ambda : This is a funny syntax that Python supports, It allows you to quickly define the minimum function of a single line, similar to a macro in C;
>>> g = lambda x:x * 2 
>>> g (3)  

>>> (Lambda x:x * 2) (3)   ;
6

Python Learning notes

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.