Python Basics-03

List:
     *Slice value [start:end] Take the content between the start and end subscripts of the specified object (left closed and right open)
     *The list can be changed, and the elements in the list can be modified in the form of slices , for example: list[1:3]=[120,90]
     *Deletion of the list: del list[subscript] or del list[start:end]
     *The data of type int cannot be converted into by list(int) * of list data
     If the list contains both numbers and strings, the list must be converted into a string in the form of a for loop;
       if there is only a string in the list, the list can be converted into a string by "".join(list)
     *The extend method of the list: the extend(self, iterable) parameter is an iterable object
Tuple : (except for immutable (first-level elements are immutable), the others are consistent with the list)
     *tuple=(1,2,) : The length of the tuple is 2, it is not that the value after the last comma is an empty value and the length of the tuple is not taken for granted. It is a 3
dictionary: lists and tuples cannot be used as the key of the dictionary, when bool is used as the key of the dictionary, Note that it will conflict with key=1 or 0; and value can be of any type
     *key-value pairs in the dictionary are unordered
     *dictionary supports del deletion
     *dictionary can perform for loop, and the key of the dictionary is printed by default, that is, the default Call dict.keys(); you can also print value, that is, call dict.values();
       You can also use dict.items() to print key-value pairs in a dictionary.
     *Magic method of dictionary:
          fromkeys(key, value): both key and value can be lists, tuples, strings
          get(key): the return value is the value corresponding to the key, if the key does not exist, return None;
          get(key, item): If the key exists, return the value corresponding to the key, if the key does not exist, return the item
          pop(key) is similar to pop(key, item)
          popitem() randomly deletes any key-value pair in the dictionary
          setdefault(key, item): If the key exists, this method has no effect, and the return value is the value corresponding to the key; if the key does not exist, the key-item key-value pair
          update ({several key-value pairs}) is generated: if the key of the key-value pair exists , then update the value; if the key does not exist, update the new key-value pair to the corresponding dictionary
          update(key=item1,key2=item2,...): same as above
     *Add:
      dic={"k1":" V1"}
      print("k1" in dic) #calls the keys() method of dic by default
      print("V1" in dic.values())
      print(("k1","V1") in dic.items())
        The above return values ​​are all True
Bool:
     *"",[],(),{},0,None are all False when converted to boolean values

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324580709&siteId=291194637