您的当前位置:首页正文

python缩进几格

来源:华佗小知识

Python的缩进方法

·使用tab键

·缩进几个空格(一般为4个)

比如下面这个例子:

>>> if True:
... print("this is true") //
... print("this is true") //
... else:
... print("this is false")//
... print("this is false")//

输出结果:

this is true
this is true

需要注意的是,虽然Python语法允许代码块随意缩进几个空格,但是位于同一个代码块中的所有语句必须保持相同的缩进,不能一下缩

进3个空格,一下缩进4个空格。