Python Beginners Small Knowledge Summary __python

Source: Internet
Author: User

1, List A, b,a=a+b efficiency is lower than a.extend (b), because the former is generated after the a+b of a new list and then assigned to a, and the latter is based on the original A to expand the B

2. The Join method of the string module is the inverse method of the split method. Eg:seq = [' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 '];sep = ', '; s = sep.join (seq)

3. The title method of the string converts the string to a title, which is the first letter of all words, and the other letters are lowercase. String = "That's all folks."; String.title () = = "That's all folks."

4, Exchange two values x,y = Y,x

5,

Use Iteritems rather than items

Iteriterms is using generators, so when iterating a large sequence is this method better

D={1: "1", 2: "2", 3: "3"}
For key, Val in D.items () # calls items () to build a complete list object
For Keys, Val in D.iteritems () # Only one value is generated per request at iteration time
This scenario and range have a similar relationship to xrange.

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.