python流程控制-条件语句If,while循环
一、If,条件语句-选择
格式:python简洁优美,注意缩进
1.第一种:
if 条件:
四个空格(tab键) 满足条件时的执行步骤
if 5>4 :
print(666)
print(777)
2.第二种:
if 条件:
四个空格(tab键) 满足条件时的执行步骤
else:
四个空格(tab键) 不满足条件时的执行步骤
3.第三种(多选):
if 条件1:
四个空格(tab键) 满足条件1时的执行步骤
elif 条件2:
四个空格(tab键) 满足条件2时的执行步骤
..............
else:
不满足上述条件时的执行步骤
4.if嵌套
name = input('请输入名字:')
age = input('请输入年龄:')
if name == '小二':
if age == '':
print(666)
else:
print(333)
else:
print('错了....')
二、while循环
while 条件:
循环体
print('')
while True:
print('我们不一样')
print('在人间')
print('痒') #死循环 ctrl+C终止循环,强制退出
print('')
终止循环:改变条件,使之不成立。
exe:从1打印到100
count = 1
flag = True
#标志位
while flag:
print(count)
count = count + 1
if count > 100 :
flag = False count = 1
while count <= 100:
print(count)
count = count + 1 count = 1
sum = 0 while count <= 100:
sum = sum + count
count = count + 1 print(sum)
终止循环:break(直接跳出循环)
print('')
while True:
print('')
print(333)
break
print(444)
print('abc')
count = 1
while True:
print(count)
count = count + 1
if count > 100:break
continue:终止本次循环,继续下次循环(相当于见底了)
print(111)
count = 1
while count < 20 :
print(count)
continue
count = count + 1
count = 0
while count <= 100 :
count += 1
if count > 5 and count < 95:
continue
print("loop ", count) print("-----out of while loop ------")
python流程控制-条件语句If,while循环的更多相关文章
- Python基础:十一、流程控制(if语句、while循环)
一.流程控制——if循环 1.第一种语法: if条件: #引号是将条件与结果分开 结果1 #四个空格,或者一个tab键,这个是告诉程序满足条件的话,运行这个结果 结果2 #如果条件是真(True)执行 ...
- Python流程控制if判断以及whlie循环
一.基本运算符补充 1. 算术运算 print(10 / 3) print(10 // 3) print(10 ** 2) 2. 赋值运算 ...
- Python—变量,条件语句,while循环,运算符,字符串等
Python初识以及变量: 变量名:——字母 ——数字 ——下划线[见名识意] (PS:数字不能开头:不能是关键字:最好不能和python内置的东西重复) ##################### ...
- python学习之条件语句(if循环)
Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块.可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非空(null)值为tru ...
- js 中的流程控制-条件语句
条件语句: if(exp)执行一句代码 <script> var x = 1 ; if(x == 1 ) //当if判断语句结果是true 或者 false 当判断结果等于true的时候, ...
- python流程控制下-for、while循环补充
循环结构之for循环 实现循环结构还可以用关键字for. for关键字 我们来看这一段代码: emotions = ['smile', 'laugh', 'cry', 'angry'] for emo ...
- python 流程控制(条件语句)
1,python流程控制单条件基本语句 2,python流程流程多条件控制语句 3,三元运算 1,python流程控制单条件基本语句 if 判断条件: 执行语句…… else: 执行语句…… 判断条件 ...
- Python学习(七) 流程控制if语句
在Python中流程控制if语句采用如下格式: if expression : statement elif expression : statement elif expression : stat ...
- Python基础之条件语句和循环
条件语句 Python中的条件语句分为 if ...else . if ...elif...else 以及if ...else 的嵌套使用: username = input('请输入您的用户名:' ...
随机推荐
- 各种图片特效,你想要吗?你不是真的想要吧?【纯CSS实现】
html部分: <!DOCTYPE html> <html lang="en" class="no-js"> <head> ...
- 随笔记录 grub引导故障修复 2019.8.7
系统备份: [root@localhost ~]# mkdir /abc [root@localhost ~]# mount /dev/sdb1 /abc [root@localhost ~]# dd ...
- 同步图计算实现pageRank算法
pageRank算法是Google对网页重要性的打分算法. 一个用户浏览一个网页时,有85%的可能性点击网页中的超链接,有15%的可能性转向任意的网页.pageRank算法就是模拟这种行为. Rv:定 ...
- sslforfree的证书合并成类似于certbot的ssl证书文件
之前的證書都是通過 certbot的命令生成的,但是目前一個服務器太多個網站,太多個ssl證書,證書過期之後,目前是 通過 ssl for free 網站再生成新的 ssl證書,再次更新證書週期 Le ...
- MySQL安装pdf介绍
pdf地址:https://files.cnblogs.com/files/pygo/mysql%E5%AE%89%E8%A3%85.pdf
- 使用pdf文本域模板生成对应的pdf
第一步: 下载jar包 <!-- itext的pdf的依赖--> <dependency> <groupId>com.itextpdf</groupId> ...
- 11 Python Libraries You Might Not Know
11 Python Libraries You Might Not Know by Greg | January 20, 2015 There are tons of Python packages ...
- 线程池_ThreadPool
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; ...
- js加密数据爬取
- 中国空气质量在线监测分析平台是一个收录全国各大城市天气数据的网站,包括温度.湿度.PM 2.5.AQI 等数据,链接为:https://www.aqistudy.cn/html/city_deta ...
- <a>标签的SEO优化细节
<a>标签的SEO优化细节 如果需要在新窗口中打开链接,我们使用的方法是在a上加上taget=“_blank”,但很多人不知道这是不符合w3c的规范的,在使用严格的DOCTYPE(xhtm ...