1 #-*-coding:utf-8-*-2 3 #1. Dictionaries4Dict = {'name':'Zara',' Age': 7,'class':' First'}5 6 #dictionary converted to string, return: <type ' str ' > {' age ': 7, ' name ': ' Zara ', ' class ' : ' First '}7 Printtype (str (dict)), str (dict)8 9 #dictionaries can be converted to tuples, returning: (' age ', ' name ', ' class ')Ten Printtuple (dict) One #dictionaries can be converted to tuples, returning: (7, ' Zara ', ' first ') A Printtuple (Dict.values ()) - - #dictionary to list, return: [' age ', ' name ', ' class '] the Printlist (dict) - #Dictionary to list - Printdict.values - + #2, meta-group -tup= (1, 2, 3, 4, 5) + A #tuple to String, return: (1, 2, 3, 4, 5) at PrintTup.__str__() - - #tuple to list, return: [1, 2, 3, 4, 5] - Printlist (tup) - - #tuples cannot be converted to dictionaries in - #3. List toNums=[1, 3, 5, 7, 8, 13, 20]; + - #list to String, return: [1, 3, 5, 7, 8, , +] the PrintStr (nums) * $ #list to tuple, return: (1, 3, 5, 7, 8, million)Panax Notoginseng Printtuple (nums) - the #list cannot be converted to dictionary + A #4. String the + #string to tuple, return: (1, 2, 3) - PrintTuple (eval ("(a)")) $ #string to list, return: [1, 2, 3] $ PrintList (eval ("(a)")) - #string converted to dictionary, return: <type ' dict ' > - PrintType (eval ("{' name ': ' Ljq ', ' age ':"))
Python string/tuple/list/dictionary cross-transfer