【问题标题】:Getting an unexpected output获得意外的输出
【发布时间】:2021-02-20 10:19:24
【问题描述】:

这是我的第一个问题!我只是在学习如何用 Python 编写代码,所以不要对我太苛刻。

我在 Python 中编写了以下类,当我调用方法 describe_restaurant(位于父类中)时,我在描述之后立即得到这个“无”输出。

我无法弄清楚为什么会发生这种情况,也无法摆脱这个“无”输出。

这是我的代码图片:

感谢您对这么糟糕的问题的帮助!

【问题讨论】:

  • 将任何代码/错误添加为格式化为代码而非图像的文本。检查Why not upload images of code/errors when asking a question?
  • 不要用describe_restaurant() 调用print(),因为describe_restaurant() 默认返回None,因为没有返回任何内容,因此您可以打印print(None)None。就做my_iceCreamStand.describe_restaurant()

标签: python class output


【解决方案1】:

在第 38 行调用:

print(my_iceCreamStand.describeRestaurant())

函数describeRestaurant() 没有返回,所以默认返回None。因此,为什么您会看到 None 打印出来。

如果您不想看到None。只需调用没有打印的函数: my_iceCreamStand.describeRestaurant()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2023-01-08
    相关资源
    最近更新 更多