相关疑难解决方法(0)

Python中的变量插值

可能重复:
在Python中打印变量的Unpythonic方式?

在PHP中,可以写:

$fruit = 'Pear';
print("Hey, $fruit!");
Run Code Online (Sandbox Code Playgroud)

但在Python中它是:

fruit = 'Pear'
print("Hey, {0}!".format(fruit))
Run Code Online (Sandbox Code Playgroud)

有没有办法让我在字符串中插入变量?如果没有,这更加pythonic怎么样?

获得参考的任何人的奖励积分

python string

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1

string ×1