python eval () uses detailed

 
1, the analytical expression (expression is str type) ---- The most common
    a = 12
    b = "Network"
    result1 = eval(a+3)        # result1 = 15
    result2 = eval ( "News" + b) # result2 = "News Network"
 
2, the string transfer list
    Requires quotation marks to wrap the content must be a list
    Right: "[2, 'a']"
    Error: "2, a" # turn after a tuple, and the content is not correct
    Error: "[2, a]" # turn results after error
    
3, the string transfer dict
    Requirements quotes wrap content must be Dictionary
    正确:'{"name":"tom","age":18}
  正确:'{"name":"tom","infos":{"size":345}}
 
4, the string switch tuple
    Requirements quotes wrap content must be tuple
    正确:'(2,"a","y")'

Guess you like

Origin www.cnblogs.com/wl-0929/p/11351016.html