【发布时间】:2019-09-20 09:10:45
【问题描述】:
这个问题涉及处理代码。
我知道您可以通过执行以下操作替换字符串中的变量:
String words = "these words";
text("I want to substitute " + words + "!", textX, textY);
但是,我想知道是否有一种方法可以像我习惯在 Python 中那样做:
words = "these words";
print('I want to substitute %s!' % words);
我发现这更具可读性,因为字符串并没有像所有类型的运算符和变量那样分割。
【问题讨论】:
-
是的,看看:
String.format("I want to substitute %s!", words);
标签: java python python-3.x string formatting