【发布时间】:2013-10-29 11:57:44
【问题描述】:
我不明白为什么 python 会给出“预期的缩进块”错误?
""" This module prints all the items within a list"""
def print_lol(the_list):
""" The following for loop iterates over every item in the list and checks whether
the list item is another list or not. in case the list item is another list it recalls the function else it prints the ist item"""
for each_item in the_list:
if isinstance(each_item, list):
print_lol(each_item)
else:
print(each_item)
【问题讨论】:
-
嗯...为什么是文字图片?只发布实际代码会更有意义......毕竟不是那么多:)可能也会更快。
-
您必须在第 3 行缩进文档字符串。
-
如果可以,请考虑在此处粘贴代码,而不是发布图片。
-
n-thing 代码截图很愚蠢的想法。此外,您必须缩进文档字符串的原因 是它们不是 cmets。它们是实际的字符串对象,由解析器附加到它们所针对的模块/类/函数(作为
__doc__属性),因此它们必须在解析树中的位置。 -
我很想知道您使用的是什么编辑器,这使得截屏然后裁剪比复制和粘贴更简单:)
标签: python indentation docstring