摘要:
continue跳出本次循环,继续下次循环 # while循环和continue配合使用 # 如果在while中 如果执行了continue 将提前结束本次循环 continue后面的代码将不再执行 # 定义一个变量 i = 0 while i < 5: i += 1 if i == 2: cont 阅读全文
摘要:
像while循环一样,for可以完成循环的功能。 在python中for循环可以遍历任何序列的项目,如一个列表或者一个字符串等。 for循环的格式: for 临时变量 in 列表或者字符串等可迭代对象: 循环满足条件时可执行的代码 # 自定义一个字符串 name = "itheima" for c 阅读全文
摘要:
三元运算 result = 值1 if 条件 else 值2如果条件为真:result =值1如果条件为假:result =值2 a,b,c = 1,3,5 d = a if a > b else c print(d) if...else if-else if 判断条件: 如果判断条件成立(True 阅读全文