Python-多个%s字符串
如何在python输出中使用多个%sPython-多个%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
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)