#-*-coding:utf-8-*-
Http://www.cnblogs.com/linjiqin/p/3674356.html
#1, Dictionaries
Dict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}
#字典转为字符串, return: <type ' str ' > {' age ': 7, ' name ': ' Zara ', ' class ': ' First '}
Print type (str (dict)), str (DICT)
#字典可以转为元组, return: (' age ', ' name ', ' class ')
Print tuple (dict)
#字典可以转为元组, return: (7, ' Zara ', ' first ')
Print tuple (dict.values ())
#字典转为列表, return: [' age ', ' name ', ' class ']
Print List (dict)
#字典转为列表
Print Dict.values
#2, tuples
tup= (1, 2, 3, 4, 5)
#元组转为字符串, return: (1, 2, 3, 4, 5)
Print tup.__str__ ()
#元组转为列表, return: [1, 2, 3, 4, 5]
Print List (TUP)
#元组不可以转为字典
#3, List
Nums=[1, 3, 5, 7, 8, 13, 20];
#列表转为字符串, return: [1, 3, 5, 7, 8, 13, 20]
Print str (nums)
#列表转为元组, return: (1, 3, 5, 7, 8, 13, 20)
Print tuple (nums)
#列表不可以转为字典
#4, String
#字符串转为元组, return: (1, 2, 3)
Print tuple (eval ("())")
#字符串转为列表, return: [1, 2, 3]
Print List (eval ("(+)"))
#字符串转为字典, return: <type ' dict ' >
Print type (eval ("{' Name ': ' Ljq ', ' Age ': 24}"))
Dictionary, meta-ancestor, list, string, convert to each other
Dictionary
Dict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}
A= Str (dict) converted to string
Print (Type (tuple (dict.values ()))) converted to progenitor
Print (List (dict.values ())) to list
Ganso
tup= (1, 2, 3, 4, 5)
Print (Type (tup.__str__ ())) converted to string
Print (list (tup)) to list
Tuples cannot be converted to dictionaries
List
Nums=[1, 3, 5, 7, 8, 13, 20]
Print (Type (str (nums))) converted to a string
Print (Type (tuple (nums)) to meta-ancestor
Tuples cannot be converted to dictionaries
String
eval = a
Print (type tuple (eval)) to progenitor
Print (list (eval)) to list
A= ' {' name ': ' Yct ', ' Age ': 10} '
>>> Eval (a) to dictionary
{' Age ': Ten, ' name ': ' YCT '}
Python string/tuple/list/dictionary cross-transfer