对于下面的代码(Python),R 中的等效代码是什么?
print("Sammy is a {}, {}, and {} {}!".format("happy", "smiling", "blue", "shark"))
最佳答案
有多种方法。我们可以使用 base R
sprintf
sprintf("Sammy is a %s, %s and %s %s!", "happy", "smiling", "blue", "shark")
[1] "Sammy is a happy, smiling and blue shark!"
或者可以使用paste/glue
考虑到这些是在全局环境中创建的对象
关于Python str.format 的 R 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71326182/