if 判断条件:
执行语句……
else:
执行语句……
举例1:
# 设定一个变量 i
i = 4
# 检查 i 是否能被 2 整除
if i % 2 == 0:
print("The value of i is even.")
else:
print("The value of i is odd.")
# 继续执行此后的代码
print("This is executed no matter the value of i.")
变量写一排,举例2:
a=1
b=2
c,d=1,4
print(a, b, c, d)
if a == c:
print("a==c")
elif a != b:
print("a != b")
else:
if a <= d:
print("a <= d")
else:
print("a > d")
input("Press Enter to exit...")
运行结果:
1 2 1 4
a==c
Press Enter to exit...