Python Base Point Introduction

Source: Internet
Author: User
Special data types

>>> List1 = [1, ' Wang ', ' tao ']>>> tuple1 = (2, ' Wang ', ' Tao ', ' Yuan ')    #tuple的内容不可更改 >>> dict 1 = {           #dict的元素分为 key:value two parts, key cannot repeat ' Wang ': ' Tao ': ' Yuan ': 100}

The use of dict, transferred from

Operationresultnoteslen (a) the number of items in a dictionary is obtained by a[k]the item of a with key K gets the value corresponding to the key K (1), (ten) a[k] = Vset A [K] to V set key K corresponding value becomes v del a[k]remove A[k] From a removes the element with the key k from the dictionary (1) a.clear () Remove all items from a clears the entire dictionary a.copy () A (shallow Copy of a Gets the dictionary copy k in Atrue if A has a key K, else false exists in the dictionary key K is returned true, no then returns False (2) k not in aequivalent to not K in a The key k does not exist in the dictionary and returns true, whereas the inverse returns False (2) A.has_key (k) equivalent to K in a, the use of the form in new code equivalent to the K in a a.items () a copy of a ' s List of (key, value) pairs gets a key, the value of the list (3) A.keys () a copy of a ' s list of keys gets the list (3) a.update ([b]) updates (and Overwri TES) Key/value pairs from B update a dictionary from the B dictionary, update if the key is the same, append (9) A.fromkeys (seq[, value]) creates a new dictionary with keys from Seq and values set to value (7) a.values () a copy of A's list of values (3) A.get (k[, X]) a[k] If k in a, else X (4) A.setdefaul T (k[, X]) a[k] If k in a, else X (also setting it) (5) A.pop (k[, X]) a[k] If k in a, else X (and remove K) (8) A.popitem () remove and return an arbitrary(key, value) pair (6) A.iteritems () return an iterator-over (key, value) pairs (2), (3) A.iterkeys () return a iterator over the Mapping's keys (2), (3) a.itervalues () return an iterator over the mapping ' s values (2), (3)

Set ([,]) is a list of key dict, with elements that are not repeatable

Special Operations

define function Def f (): F is the function name, note that you want to add a colon later

Add action Append () Append to list tail

Extend () After adding list B to a

Insert (1, ' G ')

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.