【发布时间】:2011-09-21 11:03:53
【问题描述】:
我正在使用 R。 假设我有一个城市向量,我想单独使用这些城市名称 在一个字符串中。
city = c("Dallas", "Houston", "El Paso", "Waco")
phrase = c("Hey {city}, what's the meaning of life?")
所以我想以四个单独的短语结束。
"Hey Dallas, what's the meaning of life?"
"Hey Houston, what's the meaning of life?"
...
在 Python 中是否有类似于 format() 的函数可以允许 我以简单/有效的方式执行此任务?
希望避免出现以下情况。
for( i in city){
phrase = c("Hey ", i, "what's the meaning of life?")
}
【问题讨论】: