考虑以下代码:def add_function(a, b): c = str(a) + b print \'c is %s\' % cdef add_int_function(c, d): e = c + d print \'the vaule of e is %d\' % eif __name__ ==\'__ma...
考虑以下代码:
def add_function(a, b):
c = str(a) + b
print "c is %s" % c
def add_int_function(c, d):
e = c + d
print "the vaule of e is %d" % e
if __name__ =="__main__":
add_function(59906, 'kugrt5')
add_int_function(1, 2)
它总是显示:在 a 中显示“预期有 2 个空白行,但发现有 1 个” add_int_function
,但在 add_function
.
当我在 前面添加两个空格时, def add_int_function(c, d):
末尾 unindent does not match any outer indentation level
会出现错误 add_function
:
这是 Python 社区中一个相当常见的问题。PEP 8 发布后,Python 接受了新的格式样式。其中之一规定,在类或函数的定义之后,必须有两行将它们分开。例如:
def yadayada:
print("two lines between the functions")
def secondyadayada:
print("this is the proper formatting")
所以,你永远不应该这样做:
def yadayada:
print("two lines between the functions")
def secondyadayada:
print("this is the proper formatting")
否则 PyCharm 会向您抛出该错误。