Python introductory tutorial - Judgment statement (2)

Table of contents

1. Boolean type

2. Comparison operators

3. if judgment statement


1. Boolean type

True False

result1 = 10 > 5
result2 = 10 < 5
print(result1)
print(result2)
print(type(result1))
True
False
<class 'bool'>

2. Comparison operators

==
!=
>
<
>=
<=

The result of the comparison operation is of Boolean type.

3. if judgment statement

if Condition to be judged:
    What to do when the condition is true

age = int(input())
if age >= 18:
    print("您已成年")

if Condition to be judged:
    What to do when the condition is true
else:
    The condition is not true Things to do when 

age = int(input())
if age >= 18:
    print("您已成年")
else:
    print("你还未成年")
    print("不能进入该场所")

if condition 1:
    What to do when condition 1 is true
elif condition 2:
    condition 2 What to do when the condition is true
else:
    What to do when the condition is not true 

age = int(input())
if age >= 18:
    print("您已成年")
elif age > 10:
    print("你可以打游戏了")
else:
    print("你还太小")
    print("这些你先放一放")

Guess you like

Origin blog.csdn.net/YuanFudao/article/details/132642860
Recommended