首页 > IT职业 > IT职场 > Python中if else语句出错

Python中用if……else语句编写代码,结果出现错误:
源码为:
number = 2
if number == 2:
print("you are fool")
else:
print("you are beautiful")
错误提示为:

仔细看了一下,结果是else的缩进发生了错误。
修正后的代码为:
number = 2
if number == 2:
print("you are fool")
else:
print("you are beautiful")
运行结果为:

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/964/viewspace-2833167/ ,如需转载,请注明出处,否则将追究法律责任。