【问题标题】:Python: Type errorPython:类型错误
【发布时间】:2013-09-30 10:59:30
【问题描述】:
def main():

    COUNT = 1
    food = []

    n = int(input("Enter the number of items on your grocery list.\n"))

    for i in range(1, n+1):
        food.append = (input("What is item #" + str(COUNT) + " on your list?\n", sep=""))
        COUNT = COUNT + 1

main()

我正在尝试将用户的输入添加到“食物”列表中。到目前为止,我有这个,但是当我运行它时,它给了我一个错误: TypeError: input() 没有关键字参数

有什么建议吗?

【问题讨论】:

  • 只是一个建议,但我认为您不需要变量COUNT,而是可以使用i 代替COUNT

标签: python list append typeerror keyword-argument


【解决方案1】:

只需从您的代码中删除 sep=""

【讨论】:

    【解决方案2】:

    input() 应该自己去,前面是print("Enter whatever...")。有关input() 的更多信息,请访问Python website

    【讨论】:

      【解决方案3】:

      input() 不接受任何关键字参数。 sep="" 用于打印功能。

      另外,不要指望food.append =做任何事,append是一个函数,你必须做food.append(input(...

      【讨论】:

      • 好的,现在当我运行程序时,当它提示我输入项目时,它首先显示“无”。不知道这是从哪里来的……我猜是因为我有一个空列表??
      • @user2251238 请告诉我None出现的代码行
      • @user2251238 不,请告诉我更改后的行
      猜你喜欢
      • 2016-07-02
      • 2015-06-25
      • 2014-03-04
      • 2013-09-14
      • 2014-11-30
      • 2013-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多