zoukankan      html  css  js  c++  java
  • python string to variable

    example:

    exec:执行字串语句

    >>> l=[12,3,4,4]
    >>> s = 'l.append(10)'
    >>> exec(s)
    >>> s
    'l.append(10)'
    >>> l
    [12, 3, 4, 4, 10]
    >>>

    eval:让字串变成与之对应的变量名

    >>> str = 'good'
    >>> good = 'hello!world'
    >>> eval(str)
    'hello!world'
    >>> good
    'hello!world'

  • 相关阅读:
    64_q2
    64_q1
    64_p10
    64_p9
    64_p8
    64_p7
    64_p6
    64_p5
    64_p4
    64_p3
  • 原文地址:https://www.cnblogs.com/lovemo1314/p/2755499.html
Copyright © 2011-2022 走看看