About indexes and slices in Python:
This is described in the previous view: The index value starts with 0, and 1 is the starting position from the end.
And then suddenly today, with a sense of clairvoyant, the index value starts with 0: that is, from left to right, increment by 0. -1 is from the end of the start position: that is, from right to left with-1 to start diminishing. For example:
1 ' python ']
Then: a[0] = 1, a[1] = 2, a[2] = 3, a[3] = ' python '
A[-1] = ' python ', a[-2] = 3, a[-3] = 2, a[-4] = 1
Dictionary: Define a dictionary
dict{'name':'wanan'code': ' LQ ' ' site ':'love'}
By calling the key output value, finally find using the Dict.get () function to complete
Dict.get ('name')'wanan' # output result
The following are the other operations of the dictionary:
| Method Name |
Operation |
| Dict.clear () |
Delete all elements in a dictionary |
| Dict.copy () |
Returns a copy of the dictionary (shallow copy) |
| DICT.FROMKEYSC (Seq,val=none) |
Creates and returns a new dictionary that is the key to the dictionary with the elements in the SEQ, and Val does the initial value for all the keys in the dictionary (the default is None if this value is not provided) |
| Dict.get (Key,default=none) |
The key to the dictionary dict, returns the value it corresponds to, and returns the value of default if the key does not exist in the dictionary (note that the default value of the parameter is None) |
| Dict.has_key (Key) |
Returns True if the key (key) exists in the dictionary, otherwise false is returned. After the Python2.2 version introduced in and not, this method is almost obsolete, but still provides a working interface. |
| Dict.items () |
Returns a list that contains a tuple (key, value) in the dictionary |
| Dict.keys () |
Returns a list containing the keys in the dictionary |
| Dict.values () |
Returns a list that contains all the values in the dictionary |
| Dict.iter () |
Methods Iteritems (), Iterkeys (), and itervalues () are the same as the non-iterative methods they correspond to, but they return an iteration instead of a list. |
| Dict.pop (key[, default]) |
Similar to the method get (), if the key key exists in the dictionary, delete and return Dict[key], the Keyerror exception is thrown if the key key does not exist and the value of default is not given. |
| Dict.setdefault (Key,default=none) |
Similar to Method set (), if the key key is not present in the dictionary, it is assigned by Dict[key]=default. |
| Dict.setdefault (Key,default=none) |
Similar to Method set (), if the key key is not present in the dictionary, it is assigned by Dict[key]=default. |
Problems with Python basic data types