definition | method | |
List | Can contain different types of objects, the element can be increased or decreased, may be combined with other list or a list of the split, with [] EG defined: aList = [123, 'abc', 4.56, [ 'inner', ' list '], 7-9j] | 1.list (str): to convert into a list type str, str string can be a tuple type 2.aList.append ( 'test'): is added to the list of elements to 3.del aList [1]: deleted from the list of elements the subscript 1 del aList: delete the entire list 4.cmp (list1, list2): compare the two lists size 5.len (list): returns the number of list element 6.sorted (list): using lexicographically sorting elements in the list 7.reversed (list): the inverted position of the element 8.list.count (obj) list: returns the object obj number appears in the list 9.list.extend (seq): the sequence seq content added to the list 10.list.insert (index, obj): the amount of the index index is inserted in place of the object obj 11.list.pop (index = -1): delete the specified position and returns the object, default the last object 12.list.remove (obj): Object obj deleted from the list |
Tuple | It can contain different types of objects, but are immutable and can not increase or decrease in the elements, using () to define eg: aTuple = (123, 'abc', 4.56, [ 'inner', 'list'], 7- 9j) | 1.tuple (obj): to convert into a tuple object obj objects, obj can be any string or a list of list (2) for del, cmp, len, max, min tuple method is also applicable to, but because tuples are immutable , substitutions, additions, sorting can not be achieved |
dictionary | Key-value pairs defined by {} eg: aDict = { 'name': 'cynthia', 'age': 18} | . 1.dict1 = dict (([ 'x', 1], [ 'y', 2])): dict () create a dictionary 2.dict1 = {} fromkeys (( 'x', 'y'), - 1): fromkeys () creates a default dictionary, the dictionary elements have the same value 3.dict1.keys (): Get a list of keys of the dictionary 4.dict1.has_key ( 'x'): determines whether the dictionary 'x 'key, return bool type 5.dict.get (key, default): returns the value of the key-key, if the key does not exist, the return value 6.dict.items default (): returns a list of key-value pair 7. dict.values (): returns the dictionary list 8.dict.update (dict2) all values: the dict2 list of key-value pairs added to the dictionary dict go 9.dict.pop (key): returns the value of the key key 10.setdefault (): get a similar method, it is possible to obtain a given value of the key, in addition also in auto setdefault containing no case is set to a given key corresponding key-value 11.clear (): Clear all dictionary items. Place operations, no return (return value or said None) 12.copy (): returns the new dictionary with the same key-value as a pale copy (shallow copy) |
set | set () variable set frozenset () set immutable |
Method (set of all methods): |