-2

The title may be confusing, but let’s say if I had a variable named “variable” and make it equal to a string that I would like to print out. Now, let’s say I only have a string version of the variable name. How could I print what the variable is? Here’s what I mean:

variable = “Hello!”

string = “variable”

How could I make it print “Hello” from the string?

raid6n
  • 49
  • 6

1 Answers1

3

To take your example.

variable = 'variable'

So, we just have now the value of variable, which is 'variable'.

But, if we type

globals()['variable']

OUTPUT

enter image description here

It's exactly as if you had typed variable

Lumber Jack
  • 566
  • 2
  • 8