0

i want to turn "a" to value. like:

"a" = 8

How do I "take down" the quotes and make it as value?

3 Answers 3

2

You can use globals()['a'] = 8 though there are usually better solutions for this. Also exec('a = 8') works, but don't do it.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure what you mean, but in Python 3 it isn't possible to assign a value to a string...

1 Comment

I think the author meant to assign a value to a variable with a name a. This could be beneficial, when you would like to create strings a,b,c,d, ... and assign different values to them, based on their names.
0

A string literal can not be changed. Nor can a str value of any sort. Even strings stored in values such as:

a = "some string"

The string itself "some string" can not be changed. What the identifier a is bound to can be changed though:

a = "some other string"

But no string has been changed. We just changed what object the identifier a refers to.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.