Skip to content
本页目录

if判断、比较运算符、逻辑运算符

发布时间:

if语句

格式:注意缩进 if 条件判断 : 满足条件执行部分

js
age =5
if age>4:
    print("ok")
   
js
score=input("请输入成绩")
if score==100:
    print("优秀")
if score==60
    print("及格")
   

当输入100时没有输出,是因为input()获取的值默认为字符串所以:

js
score=input("请输入成绩")
if score=='100':
    print("优秀")
if score=='60'
    print("及格")
   

运算符

1、比较运算符

| -- | -- | -- | | == | 比较等 | 2==3 | | != | 不等于 | 2!=3 | | > | 大于 | 2>3 | | < | 不等于 | 2!=3 | | >= | 大于等于 | 2>=3 | | <= | 小于等于 | 2<=3 |

2、逻辑运算符

| -- | -- | -- | | and | 逻辑与 | 2==3 | | or | 逻辑或 | 2!=3 | | not | 逻辑非 | 2>3 | 逻辑运算结果输出格式为True或False 运算中值为1或0

js
print((1<3)
# 输出True
print(((1<3)+3)
# 输出4
   

and

js
a="哈哈"
b="呵呵"
if a=="哈哈" and b == "呵呵":
    print("都在笑")
   

or

js
fruit="苹果"
if fruit=="苹果" or fruit == "水蜜桃":
    print("水果")