Python条件if语句

Python条件if语句,python,Python,我是python的初学者,在学习python的过程中,我在执行if语句时出错 有人能告诉我代码中遗漏了什么吗 文件“Demo\u class2\u Conditions.py”,第8行 打印(X) ^ 缩进错误:应为缩进块 您应该始终在条件之后缩进属于块的语句(2或4个空格) 您的示例可以正确缩进,如下所示: # first evaluation starts with no indentation if X > Y: print(X) # single statement (blo

我是python的初学者,在学习python的过程中,我在执行
if
语句时出错

有人能告诉我代码中遗漏了什么吗

文件“Demo\u class2\u Conditions.py”,第8行
打印(X)
^
缩进错误:应为缩进块

您应该始终在条件之后缩进属于块的语句(2或4个空格)

您的示例可以正确缩进,如下所示:

# first evaluation starts with no indentation
if X > Y: 
  print(X) # single statement (block 1) if previous condition satisfied
else:
  # block 2 begins
  print(Y)
  # block 2 ends

# second evaluation starts with no indentation
if Y > Z:
  print(Y) # block 3 has only 1 statement
else:
  print(Z) # single statement is block 4

# everything after evaluating is not indented
# first evaluation starts with no indentation
if X > Y: 
  print(X) # single statement (block 1) if previous condition satisfied
else:
  # block 2 begins
  print(Y)
  # block 2 ends

# second evaluation starts with no indentation
if Y > Z:
  print(Y) # block 3 has only 1 statement
else:
  print(Z) # single statement is block 4

# everything after evaluating is not indented