缩进错误:预计缩进块python 3.6
我是python中的新手。我想返回字符串“关闭”,如果s==yes
。请告诉我在下面的代码中可能出错。缩进错误:预计缩进块python 3.6
def shut_down(s):
... if s == "yes":
File "<stdin>", line 2
if s == "yes":
^
IndentationError: expected an indented block
TL;医生尝试为4个空格添加到您这样第二行的开始:
def shut_down(s):
if s == "yes"
建议在Python中使用4个空格作为缩进,列表或不同数量的空格可能有效,但也有时会引起麻烦。更多的可以在PEP8上阅读。
我不完全确定你是如何试图缩进第二行的,但重要的是要注意大多数现代Python IDE会自动替换4个空格的制表符,如果你习惯于制表符我个人使用PyCharm,但IDLE也是这样做的)。
给出空格或标签。 Python强制缩进。 ...并不意味着光标向前移动,而是写入一个块。
复制下面的两个代码片段,并尝试运行
def shut_down(s):
print "Indentation Error"
def shut_down(s):
print "No Indentation Error"
我假设你是在Python函数的定义非常初学者,自定义函数的正确方法是:
#function definition
def shut_down(s):
if s=="yes" :
print("right")
return
shut_down("yes") #calling the function
功能在这里给你分配“是” 小号变量。
文件 “
文件 “
高清shut_down(S): 如果s == “是”: 文件 “
您需要使用4个空格进行缩进。
def shut_down(s):
if s == "yes":
删除点'...'并使用'4个空格或一个制表符'作为标识。 –
代码中的小点是什么?或者你混合选项卡和空间? – danche
欢迎来到SO。请尝试在平台上搜索类似的问题,并在发布您的问题之前阅读python文档。 – Sadik