ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## if 与else 是同级别的 ## &&变成了 and || 变成了 or ~~~ a = 100 if a == 100: if 100 == 100 and 100>300: print(a) else: print("嵌套成功") print("嵌套成功1212") print("嵌套成功5345455") else: print("hahha %s" % a) ~~~ ## 子语句要缩进4个空格 相当于{}里的 ~~~ a = 100 if a == 100: print(a) else: print("hahha %s" % a) ~~~ ## if多条件判断 else在python里改为了 elif ~~~ a = 100 if a == 100: print(a) print(a) elif a <= 100: print("hahha %s" % a) ~~~ ![](https://img.kancloud.cn/85/7c/857cc9df4b71cdde343e449af576c7d4_1016x537.png) ![](https://img.kancloud.cn/36/da/36daabeeb3330d9a55f85578d2add60f_2051x1138.png) ## 嵌套判断: ## 嵌套使用首行缩进来进行判断属于哪个代码块 ~~~ a = 100 if a == 100: if 200 == 200: print(a) else: print("hahha %s" % a) ~~~ ![](https://img.kancloud.cn/63/54/63544f89023c5bd30ff514fa217166bf_2519x1476.png) ![](https://img.kancloud.cn/df/08/df0816507d4ab0917b8edbea0cb57aba_2375x1432.png)