Skip to main content
 首页 » 编程设计

python之在 python 和 coffeescript 中将变量插入字符串

2024年10月25日30del

在 python 中:

namespace = { 'host': 'facebook.com', 'user': '{somehost}/user/83426347' } 
namespace['user'].format(somehost=namespace['host']) 

facebook.com/user/83426347

在 CoffeeScript 中我有相同的:

namespace= 
    host: 'facebook.com' 
    user: 'facebook.com/user/42342342' 

我是 CS 的新手,所以如何处理与 python 相同的行为?

请您参考如下方法:

python

language = "Python" 
greet = "I love %s" % language 

CoffeeScript

language = "Coffescript" 
greet = "I love #{language}"