python 代码缩进

python 不像其他程序设计语言(java和C语言)需要使用大括号 {}分割代码块, 而是采用缩进和冒号“:” 来区分代码之间的层次。

缩进的空格数是可变的,但是同一个代码块的语句必须包含相同的缩进空格数。实例如下:

if True:
    print ("True")
else:
    print ("False")

错误示例

if True:
    print ("Answer")
    print ("True")
else:
    print ("Answer")
  print ("False")    # 缩进不一致,会导致运行错误
   File "test.py", line 6
    print ("False")    # 缩进不一致,会导致运行错误
                                      ^
IndentationError: unindent does not match any outer indentation level

猜你喜欢

转载自blog.csdn.net/imxlw00/article/details/84979532