chap4 条件

chap4 条件

1.if语句

if ():



···
<following_statement>
如果输入正确则会执行程序,否则不会执行if语句里的内容

if else语句

```
x=input("x=")
x=float(x)
print("hello")
if x<10:
   print("wahoo")
else:
   print("oh no")
print("goodbye")
```

if else有选择性 可以有嵌套

if-elif-else语句

```
print("hello")
if x < 10:
    print("wahoo")
elif x <=99:
    print("meh")
else:
    print("hahahaha")
print("goodbye")
```

if x<10为真会输出wahoo 如果x>10且<=99输出meh 否则输出hahahaha

match-case语句

```
def f(x):
    match x:
       case 400:
			return "A"
	   case 404:
			return "B"
       case 418:
            return "C"
       case_:
            return "not found"  
```

类似于switch-case语句

posted @   xiruan  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示