【问题标题】:Python print variable not enough arguments for format string [duplicate]Python打印变量没有足够的格式字符串参数[重复]
【发布时间】:2019-10-26 02:09:51
【问题描述】:

我有一段代码只是从 json 列表中打印出用户名并随机生成密码

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

但我收到以下错误:

        print ('sending username %s and password %s' % username, password)
TypeError: not enough arguments for format string

【问题讨论】:

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

标签: python


【解决方案1】:

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)

【讨论】:

    猜你喜欢
    • 2012-07-09
    • 2014-04-07
    • 1970-01-01
    • 2016-04-16
    • 2012-11-06
    • 2017-12-15
    • 2020-11-23
    • 2018-05-09
    • 1970-01-01
    相关资源
    最近更新 更多