1. Dictionaries
Dict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}
Dictionary converted to string, return: <type ' str ' > {' age ': 7, ' name ': ' Zara ', ' class ': ' First '}
Print type (str (dict)), str (DICT)
Dictionaries can be converted to tuples, returning: (' age ', ' name ', ' class ')
Print tuple (dict)
#字典能够转为元组, return: (7, ' Zara ', ' first ')
Print tuple (dict.values ())
Dictionary to list. return: [' age ', ' name ', ' class ']
Print List (dict)
Dictionary to List
Print Dict.values
2, meta-group
tup= (1, 2, 3, 4, 5)
Tuple to String, return: (1, 2, 3, 4, 5)
Print tup.__str__ ()
Tuple to list, return: [1, 2, 3, 4, 5]
Print List (TUP)
Tuples cannot be converted to dictionaries
3. List
Nums=[1, 3, 5, 7, 8, 13, 20];
List to String, return: [1, 3, 5, 7, 8, 13, 20]
Print str (nums)
List to tuple, return: (1, 3, 5, 7, 8, 13, 20)
Print tuple (nums)
List cannot be converted to dictionary
4. String
The string is converted into a tuple. return: (1, 2, 3)
Print tuple (eval ("())")
String to list, return: [1, 2, 3]
Print List (eval ("(+)"))
String converted to dictionary, return: <type ' dict ' >
Print type (eval ("{' Name ': ' Ljq ', ' Age ': 24}"))
Python strings, lists, tuples, dictionaries convert each other