day07 summary

Tuple built-in method

What is the tuple (tuple): not only desirable to change the list, create a tuple was written dead

  1. Role: to create a tuple was written dead

  2. :( spaced manner defined) within the plurality of elements with a comma (which may be of any data type)

    If only one element tuple must have a comma

  3. Instructions

    1. Index values
    2. Index sliced
    3. for loop
    4. Member operator
    5. len length
    6. index acquisition element index
    7. count count
  4. Ordered or unordered

    Ordered

  5. Variable or immutable

    There is not this say

Defined Ganso - "small memory -" Write dead

Dictionary built-in method

  1. effect

    Storing a plurality of data, each data having a description of

  2. Defined way

    {} Are separated by commas plurality of keys within key (descriptive sense, not the variable data type): value of the value (of any data type) of

  3. Use

    1. Press the key value / modified value by key
    2. Add value, not just to add, modify it there
    3. for loop
    4. Member operator
    5. len length
    6. keys/values/items
    7. get get (no return None, can be given a default value
    8. update update (equivalent to the list in the extend)
    9. fromkeys
    10. setdefault (add only not modify)
  4. Ordered or unordered

    Disorderly

  5. Variable or immutable

    variable

Hash / hash table to store data

Compared list, hash tables, insert / delete data faster

  1. First, the key did hashing (hash can can handle all data types): Mersenne Twister (pseudo-random number generation) -> by hashing he can generate a sequence for each key (never repeat the same thing hashed into the same result)
  2. Hash function sequence just generated (pure digital), in addition to pure digital modulo 9 (0,1,2,3,4,5,6,7,8)

A collection of built-in method

What is the set: intersection / union / complement / set difference

  1. effect

    1. For the calculation
    2. Deduplication
    3. Out of order - "a hash-based implementation
  2. Defined way

    {} The plurality of elements separated by commas (variable data types may not be)

    Empty dictionary
    s = {}
    empty set
    s = set {}

    s = { 'a', ' a', 'a', 'a', 1, 'v', 2, 2, 'c', 3, 3, 4, 5, 6} # for digital purposes, not will be out of order; but for others, it is scrambled
    print (s) # {1, 2, 'a', 'c', 3, 4, 5, 6, 'v'}

  3. Instructions

    1. Union

      print(pythoners | linuxers)

    2. Intersection

      print(pythoners & linuxers)

    3. Difference set

      print(pythoners - linuxers)

    4. Complement

      print(pythoners ^ linuxers)

    5. add

      pythoners.add('oscar')

    6. pop delete a random

      pythoners.pop()

  4. Ordered or unordered

    Disorderly

  5. Variable or immutable

    variable

Data Type Summary

Number of stored-value

A stored value: integer / floating point / string
stored plurality of values: a list / tuple / dictionary / collection

Ordered or unordered

Ordered: string / list / tuple (sequence type)
unordered: dictionary / collection

Variable or immutable

Variable: List / dictionary / set
immutable: integer / floating point / string / tuple

Copy depth (only for variable data type)

Copy depth

copy

When y is a copy of the object x, if x is immutable, changes x y unchanged; if x is a variable type, x becomes y changes.

Shallow copy

If list1 list2 shallow copy of the object, the immutable elements within list1 changed, list2 unchanged; if the variable element in list1 changed, the change will follow list2.

Deep copy

If list1 list2 is deep copy of the object, the immutable elements within list1 changed, list2 unchanged; if the variable element in list1 changed, list2 not change, i.e. list1 list2 never change because of change.

Guess you like

Origin www.cnblogs.com/whkzm/p/11529925.html