查看: 10  |  回复: 0
  Python 条件语句if-elif-else和变量写一排
楼主
发表于 昨天 14:25
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...


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com