我有多个字符串需要原始字符串来附加不同的字符串。根据我的知识,origin string和append string都包含1个int变量,下面的代码都可以工作,但是最好的方法是什么,或者有更好的方法吗? 或者有没有办法让我写下
newstrg = '{}{}'.format(org%OrgInt, appd%appdInt)
第一种方法
org = "org__%s"
appd = "appd__%s"
orgInt = 1
appdInt = 7
newstrg = org % orgInt + appd % appdInt
print(newstrg)
org__1appd__7
第二种方法
org = "org__{}"
appd = "appd__{}"
orgInt = 1
appdInt = 7
newstrg = (org + appd).format(orgInt, appdInt)
org__1appd__7
还有一种方法:
“org{org}appd{appd}”格式(org=1,appd=7)或类似格式如何?您的格式字符串可以是任意的,使用命名占位符更方便。你知道吗
编辑
如果令牌和数字是可变的,则将它们作为令牌-值对列表输入:
相关问题 更多 >
编程相关推荐