Python打印变量的格式字符串参数不足

时间:2019-06-11 15:43:32

标签: python

我有一段代码,仅打印json列表中的用户名,并随机生成了密码

if (toCast.GetType() == typeof(Parent)) { return new InstanciatedFromGenericClass((Parent)toCast); } if (toCast.GetType() == typeof(Child)) { return new InstanciatedFromGenericClass((Child)toCast); }

但是我收到以下错误:

print ('sending username %s and password %s' % username, password)

1 个答案:

答案 0 :(得分:0)

print ('sending username %s and password %s' % username, password)的意思是:

  

使用两个参数调用print

     
      
  • 'sending username %s and password %s' % username
  •   
  • password
  •   

第一个字符串没有足够的格式参数(一个而不是两个)。您打算使用元组

'sending username %s and password %s' % (username, password)