string as variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ams Ams
    New Member
    • Nov 2011
    • 1

    string as variable

    My code will print 'tab1' but want to print '143' (tab1 value). How????
    Code:
    tab1=143
    t='tab'+'1'    #it mean tab1
    print t
    Last edited by bvdet; Nov 22 '11, 01:28 AM. Reason: Add code tags, clarify question
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Built-in function eval().
    Code:
    >>> tab1=143
    >>> t = 'tab'+'1'
    >>> t
    'tab1'
    >>> eval(t)
    143
    >>>

    Comment

    Working...