📌  相关文章
📜  如何在python代码示例中使用字符串变量作为变量名

📅  最后修改于: 2022-03-11 14:47:04.556000             🧑  作者: Mango

代码示例1
#works only inside classes
name  = 'varname'
value = 'something'

setattr(self, name, value) #equivalent to: self.varname= 'something'

print (self.varname)
#will print 'something'