今天将是基础篇的最后一篇,咱们来补上最后一个内容,流程控制for循环 For 循环 一.为什么有for循环? for循环能做的事情,while循环全都可以实现,但是在某些情境下,for循环相对于while循环效率更高,例如遍历列表,for循环可以极大简化代码的数量 二.基本结构 # for循环 for i in 循环体: 代码1 代码2 ... 示例1: >>> list = [1,2,3,4,5,6] >>> for i in list: ... print(i) .…
一:流程控制if 语法一: if 条件: code1 code2 code3 ... age = 20 height = 170 weight = 60 sex = 'female' is_beautiful = True if age> 12 and age<25 and weight == 60 and height >168 and sex == 'female' and is_beautiful: print('这就是我的晓晖女神') 语法二 if 条件: code1 code2…
今日目录: 一.流程控制 1. if 2. while 3. for 4. 后期补充内容 一.流程控制--if 1.if判断: # if判断 age = 21 weight = 50 if age > 18 and age < 25 and weight >40 and weight < 60: print("表白...") 2.if+else: # 语法二:if - else age = 21 weight = 50 if age > 18 and ag…