python - 缩进错误 : expected an indented block python 3. 6

标签 python indentation

我是Python新手。我想返回字符串“shutting down” if s==yes 。请告诉我下面的代码中可能有什么问题。

def shut_down(s):
... if s == "yes":
  File "<stdin>", line 2
    if s == "yes":
     ^
IndentationError: expected an indented block

最佳答案

我假设您是Python函数定义的初学者,定义函数的正确方法是:

    #function definition
    def shut_down(s): 
      if s=="yes" :
        print("right")
      return 

    shut_down("yes")  #calling the function

在函数调用期间,您将“yes”分配给s变量。

关于python - 缩进错误 : expected an indented block python 3. 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44612393/

相关文章:

c++ - switch 语句的格式化

jasper-reports - 使用 JasperReports 在生成的 PDF 中缩进

c# - ScintillaNET 中的缩进和智能缩进

vim - 如何在 Vim 中缩进光标上方的多行?

python - 在矩阵中每隔一行添加一个新行,其元素是其上方和下方元素的平均值

python - 对 reversed() 函数的误解?

python - 我的 setup.py 在 python 3.8.1 中安装所有依赖项有什么问题

python 远程数据库连接mysql

python - Matplotlib 使用 ax.set() 旋转 xticklabels

python - Python 的原子编辑器缩进错误