A variables variables
Terry Reedy
tjreedy at udel.edu
Sat Aug 23 21:24:29 EDT 2008
Gandalf wrote:
> how can I declare a variable with another variable name?
>
> for example I will use PHP:
>
> $a= "hello";
>
> $a_hello="baybay";
>
> print ${'a_'.$a) //output: baybay
>
>
> how can i do it with no Arrays using python
Others have given you the direct answer. But using lists or dicts is
almost always a better solution in Python than synthesizing global/local
namespace names.
a={'hello':'baybay'}
print a['hello']
More information about the Python-list
mailing list