python03- list

1 slice list of formulas

    If empty, take to the head, left to take, do not take the right

Colon left empty, it is necessary to offset from the beginning of taking element 0; the right space, it is necessary to take the last element of the list. : Figures left of the colon corresponding elements bring, not the right move.

2 append () add elements

A week later, you're on the class too, headmaster suddenly picking up a new student "Little America", said to be a transfer student, I want to plug into your class. At this point, we need to use append () function to increase the list of elements, append mean additional, supplemental. In brackets after the append only takes one argument, but to two, that is, 4 and 5. So, with the append () to add elements list, you can only add an element.

3 del () Delete

Real del statement on the very convenient, both to delete an element, can also delete multiple element once (similar to the principles and slice, take the left and right do not take)

4 Dictionary

Dictionary keys have a unique property, and the value may be repeated. That dictionary can not contain two 'Bob' is key, but it can have the same for the two 90 values

Now, we try to print out the results of Xiao Ming from the dictionary. This index involves the dictionary, and a list of different indexed by offset, by the dictionary is key.

We can find: the code key to delete the dictionary is the del statement del dictionary name [key], and add key-value pairs to use assignments dictionary name [key] = value.

5 and dictionaries difference

   5.1 lists and dictionaries, if you want to modify elements are available to complete the assignment.

   5.2 supports nested arbitrarily. In addition to the previously learned data type, and list of other lists can be nested dictionaries, dictionaries and other dictionaries can be nested list.

 

 

Guess you like

Origin www.cnblogs.com/xiangnianchulian/p/12574910.html