Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-多个%s字符串_Python_String - Fatal编程技术网

Python-多个%s字符串

Python-多个%s字符串,python,string,Python,String,如何在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

如何在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)
更好:使用


您需要使用元组:

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

也可以考虑使用.

我喜欢使用字符串格式。

所以


给出元组中的所有变量,如下所示:

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

两者都是无效的Python.Syntex错误出现在“,%(Fname,Lname)”中,右边的一个是%(Fname,Lname)
TEXT ='Hi, your first name is {} and your last name is {}'.format(Fname, Lname)
TEXT = 'Hi, your first name is %s', % (Fname)
TEXT = 'Hi, your first name is %s and your last name is %s' % (Fname, Lname)
TEXT = 'Hi, your first name is {} and your last name is {}'.format(Fname, Lname)
TEXT = 'Hi, your first name is %s and your last name is %s.' %(Fname,Lname)