python - 在python中连接变量名

标签 python r

我有一组表名

1. EOM
2.STMT
3.查找等

我想将这些表名与一些变量名相关联,例如

1.开始时间,
2.结束时间,
3. total_time 等

我想写这些变量名的方式类似于

1. start_time_EOM, end_time_EOM, total_time_EOM
2. start_time_STMT, end_time_STMT,total_time_STMT
3. start_time_LOOKUP,end_time_LOOKUP,total_time_LOOKUP

这可以在 python 中完成,如何完成?
(注意:我是 Python 新手,仍在努力学习)。

最佳答案

是的,字典是解决方案:

tables=["A","B","C"]
vars = ["var1","var2","var3"]
dict={}
for val in tables:
  for val2 in vars:
    dict[val2+"_"+val] = foo
    dict[val2+"_"+val] = bar
    dict[val2+"_"+val] = foobar
#and so 

希望如果有帮助

关于python - 在python中连接变量名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44974936/

相关文章:

r - 为什么我的行名称被删除以及如何避免它?

r - 使用treemapify ggplot图例键和标签之间的间距

python - 无法在 Pycharm 中导入 azure.functions

python - 球坐标中的蒙特卡罗积分

python - 简单千层面网络输出很慢

javascript - Shiny 模块和 renderUI 传递 javascript 代码

python - 我如何使用 Python(精确到分钟)计算过去 30 天的时间?

python - 使用GPXPY解析gpx文件导致not well-formed invalid token错误

r - 在 R 中安装 PKI 包时出错

r - 如何在ggplot中缩短X轴标签文本?