You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Notebook中Python自定义函数无输出问题咨询

问题分析与解决

Hey there! Let's figure out why your code isn't producing any output.

First, let's break down the issues in your code:

  • Missing the def keyword: In Python, you must start every function definition with def — without it, the interpreter doesn't recognize your line as a valid function declaration. That's a critical oversight here.
  • Incorrect indentation: Python uses indentation to group code into blocks. If your print statements aren't indented under the function definition, they won't be part of the function's body, so calling the function won't trigger them.

Here's the fixed version of your code, formatted correctly:

def say_cheese():
    print("Say cheese, kids!")
    print("Cheese!")

say_cheese()

What did we fix?

  1. Added def before say_cheese() to properly define the function.
  2. Indented both print statements with 4 spaces (the Python standard) so they're tied to the say_cheese function.
  3. Placed the function call say_cheese() on a new line after the function definition for better readability.

When you run this corrected code, you'll see both lines printed out exactly as you expect.

If you prefer writing the function in a single line (though it's less readable), this version also works:

def say_cheese(): print("Say cheese, kids!"); print("Cheese!")
say_cheese()

Either way, the core fixes are adding the def keyword and structuring the function body with proper indentation.

内容的提问来源于stack exchange,提问作者T.Amit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:14:48