【python小随笔】动态创建变量名,并且赋值
PS:这个玩法很有意思,pycharm还会飘红,
t = ['B0716PK6R2','B077X9J24C','B01N2SBH4J'] count = 0 names = locals() for asin in t: count = count+ 1 names['asin' + str(count)] = asin print(asin1,asin2,asin3)
# 输出结果:
B0716PK6R2 B077X9J24C B01N2SBH4J
Python全栈(后端、数据分析、脚本、爬虫、EXE客户端) / 前端(WEB,移动,H5) / Linux / SpringBoot / 机器学习