Python reading notes-chapter III, chapter Four

Source: Internet
Author: User
Tags print format string find

Chapter III1. String formatting >>>format= "Hello%s%s World" >>>values= (' World ', ' hot ') >>>print format% values # You can also receive a single string, or you can use%f%d, similar to C's printf, to match multiple parameters with parentheses >>> '%s plus%s equals%s '% (1,1,2)
>>> '%010.2f '% pi ' 0000000003.14 ' represents altogether 10 seats 0, integers, decimal points, fractional parts

2. Operation of the string find or find (' xx ', start,end) str.find (' xxx ') #返回字符串的位置
Join, Split's inverse method. For example s=[1,2,3,4] flag= ', ' flag.join (s), 1,2,3,4
Replace (SOURCE,XXXX) replacement
3. Conversion table Table=maketrans (' Ca ', ' BD ') word= ' HelloWorld '. Translate (table)
Fourth ChapterThis part of the content is written less than a log1. Creation of dictionaries>>>items={' Alice ': ' 1234 ', ' bob ': ' 4567 '}{} is an empty dictionary2.dict functiond=dict (Two-dollar key-value team) such as [(' A ', 1 '), (' B ', 2)]3. Basic OperationLen (d)D[k]del D[k]K in D4. Formatting stringstemplate= ' Print template% {' title ': ' Hello '}5. The method of the dictionaryClear ClearRemoveCopy # y=x.copy ()deep copy: Deepcopy # dc=deepcopy (d)The Get access dictionary does not error, and setting does not exist when the value get (key, ' Error infor ') Fromkeys Create an empty dictionary, only the keys such as {}.fromkeys ([' Name ', ' age ']) has_keyitems No order iteritems return iterator pop (key) Delete Popitem Delete last update
most of the functions do not need to memorize, use the time to turn over notes, separate check usage, used when familiar.


Python reading notes-chapter III, chapter Four

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.