开发者

what python function replace functionaly for php operator $$

hi in php im able to create variable like this

$param = array('product', 'brand');
foreach ($param as $item) {
  $$item = $item;
}

so the result will be

$product = 'product';

how can i achieve 开发者_如何学JAVAthis in python?

param = ['product', 'brand']
for item in param:
  ??? = item


You can't, sanely. Use a dict instead.

items = {}
for item in param:
  items[item] = item


param = ['product', 'brand']
for item in param:
  globals()[item] = item

But it's not a good idea to do so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜