运算符and编码
- 循环
- while条件:
- 代码块(循环体)
代码插入 死循环 count=1 while count : print('王二') count=count+1 # '王二'.... 数数 1-100 count=1 while count<100: print(count) count=count+2 # "1 3 5 7 9 ..." 让用户一直输入内容并打印,直到输q退出 while True: content=input('请输入一句话,(输入q退出)') if count =='q': break # 终止当前本层循环 print(content)
- else:
- 当上面的条件为假,才会执行
- 执行顺序:
- 判断条件真假,若真,执行循环体,然后再次判断条件...直到循环条件为假,程序退出
- break和continue
- break:停止当前本层循环
- continue:停止当前本次循环,继续执行下一次循环
- 格式化输出
- %s占位字符串
- %d占位数字
- 基本运算符
- and: 并且,同真则真
- or: 或,一真则真
- not: 非真既假,非假既真
- 顺序: ()=>not=>and=>or
- x or y:
- 若x是零,输出y
- 若x非零,输出x
- True: 非零
- Flase: 零
编码