gpt4 book ai didi

Python - 多个 %s 字符串

转载 作者:行者123 更新时间:2023-12-02 11:42:15 25 4
gpt4 key购买 nike

如何在 python 输出中使用多个 %s?

TEXT = 'Hi, your first name is %s' %Fname

这工作正常,但是......

TEXT = 'Hi, your first name is %s and your last name is %s' %Fname %Lname

我收到错误

TypeError: not enough arguments for format string

最佳答案

使用元组:

TEXT = 'Hi, your first name is %s and your last name is %s' % (Fname, Lname)

更好:使用str.format(*args, **kwargs) .

"Hi, your first name is {0} and your last name is {1}".format("foo", "bar")

关于Python - 多个 %s 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24694374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com