Python string/tuple/list/dictionary cross-transfer
--coding:utf-8--1, Dictionary dict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '} dictionary converted to string, return: <type ' str ' > {' age ': 7, ' name ': ' Z Ara ', ' class ': ' First '}print type (str (dict)), the STR (dict) dictionary can be converted to tuples, returning: (' age ', ' name ', ' class ') the print tuple (dict) dictionary can be converted to tuples, Return: (7, ' Zara ', ' first ') print tuple (dict.values ()) dictionary to list, return: [' age ', ' name ', ' class ']print list (dict) dictionary to list print Dict.values2, tuple tup= (1, 2, 3, 4, 5) tuples converted to strings, returned: (1, 2, 3, 4, 5) print tup.str () tuples to list, return: [1, 2, 3, 4, 5]print list (tup) tuples cannot be converted to Dictionary 3, List nums=[1, 3, 5, 7, 8, 13, 20]; list converted to string, return: [1, 3, 5, 7, 8,, 20]print str (nums) to tuple, return: (1, 3, 5, 7, 8, and) print The list of tuple (nums) can not be converted to dictionary 4, string string to tuple, return: (1, 2, 3) Print tuple (eval ()) string to list, return: [1, 2, 3]print list (eval ()) The string is converted to a dictionary, returning: <type ' dict ' >print type (eval ({' name ': ' Ljq ', ' Age ': 24}))
Python string/tuple/list/dictionary cross-transfer