【问题标题】:I'm getting ''none'' instead of result我得到“无”而不是结果
【发布时间】:2021-09-13 11:44:35
【问题描述】:

您好,我是 Python 初学者。我编写了一个东西只是为了练习,但我得到的是“无”而不是结果。代码是这样的: code

我认为我使用 str 函数错误,但我不知道如何修复它。 感谢您的帮助

【问题讨论】:

  • 请发布代码,而不是代码的图片
  • 这是因为你没有返回任何东西。当您不返回任何内容时,函数默认返回None。因此结果
  • 您使用的是哪个 Python 版本,您是否在 bigquery 中运行它?

标签: python python-3.x list python-2.7


【解决方案1】:

none 告诉您该函数没有返回值,因此您必须使用 return 关键字

【讨论】:

    【解决方案2】:

    你应该使用而不是print

    def work_time(mathematic, chemistry, biology): 
        return mathematic*2 + chemistry*1 + biology*(0.5)
    print("I will study " + str(work_time(1, 2,3) ) + " hours today")
    

    【讨论】:

      【解决方案3】:

      看,当你不使用return 关键字时,函数会返回None。所以当你打印一个返回None的函数时,None就会被打印出来。

      所以,请使用 return 关键字。

      def work_time(mathematic, chemistry, biology): 
          print(mathematic*2 + chemistry*1 + biology*(0.5))
          return mathematic*2 + chemistry*1 + biology*(0.5)
      print("I will study " + str(work_time(1, 2,3) ) + " hours today")
      

      【讨论】:

      • 欢迎@forscythe2,
      【解决方案4】:

      我看不到图片或代码 但不会导致任何结果的事情可能是:- 1.没有从函数返回蓝色 2.保持布尔非活动状态 3.不定义代码

      【讨论】:

        猜你喜欢
        • 2017-04-06
        • 2023-02-10
        • 2021-04-11
        • 2010-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-07
        相关资源
        最近更新 更多