开发者

what python function replace functionaly for php operator $$

开发者 https://www.devze.com 2023-03-06 12:56 出处:网络
hi in php im able to create variable like this $param = array(\'product\', \'brand\'); foreach ($param as $item) {

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

精彩评论

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