Author's blog address: https://www.cnblogs.com/liu-shuai/
Eval
Function: evaluates the string str as a valid expression and returns the result of the calculation.
Syntax: eval (source[, globals[, locals]), value
Parameters:
Source: The code object returned by a Python expression or function compile ()
Globals: Optional. It must be dictionary.
Locals: Optional. Arbitrary map Object
Examples show:
you can convert list,tuple,dict and string to each other. #################################################string conversion to list>>>a ="[ [up], [3,4], [5,6], [7,8], [9,0]]">>>type (a)<type'Str'>>>> B =Eval (a)>>>Printb[[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]]>>>type (b)<type'List'>#################################################convert strings into dictionaries>>> A ="{1: ' A ', 2: ' B '}">>>type (a)<type'Str'>>>> B =Eval (a)>>>Printb{1:'a', 2:'b'}>>>type (b)<type'Dict'>#################################################string Conversion Narimoto Group>>> A ="([up], [3,4], [5,6], [7,8], (9,0))">>>type (a)<type'Str'>>>> B =Eval (a)>>>PrintB ([1, 2], [3, 4], [5, 6], [7, 8], (9, 0))>>>type (b)<type'tuple'>
Python eval function Magical