python的条件判断和循环(浅谈Python基础—判断和循环)
类别:脚本大全 浏览量:2574
时间:2021-10-30 10:33:22 python的条件判断和循环
浅谈Python基础—判断和循环判断
缩进代替大括号。
冒号(:)后换号缩进。
if
|
test = 100 if test> 50 : print ( 'ok' ) print ( 'test' ) |
if-elif-else
|
test = 50 if test> 200 : print ( '200' ) elif test< 100 : print ( '100' ) else : print ( '100-200' ) |
列表
|
test1 = [ 123 , 456 , 789 ] if 123 in test1: print ( 'ok' ) |
字典
|
test2 = { 'hello' : 123 , 'world' : 456 } if 'hello' in test2: print ( 'ok' ) |
循环
while
数值
|
test = 0 while test< 10 : print (test) test + = 1 |
集合
|
test1 = set ([ 'hello' , 'world' ]) while test1: test2 = test1.pop() print (test2) |
for
集合
|
test3 = set ([ 'hello' , 'world' ]) for t in test3: #相当于foreach print (t) |
列表
|
test4 = [ 123 , 456 , 789 ] for i in range ( 3 ): print (test4[i]) |
|
test5 = [ 123 , 456 , 789 , 34 , 5435 , 26 , 2362 , 262 , 26 , 5 ] for i in range ( len (test5)): print (test5[i]) |
continue
|
test6 = [ 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 ] for i in test6: if i % 2 = = 0 : print (i) else : continue print (i) |
break
|
test7 = [ 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 ] for i in test7: if i % 2 = = 0 : print (i) else : break print (i) |
以上所述是小编给大家介绍的python基础—判断和循环详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对开心学习网网站的支持!
原文链接:https://www.cnblogs.com/gloria-zhang/p/10572125.html
您可能感兴趣
- pythondjango后台管理(基于腾讯云服务器部署微信小程序后台服务Python+Django)
- python 提取微信消息(python实现文件助手中查看微信撤回消息)
- python中的变量与变量类型(Python变量类型知识点总结)
- python线程池如何实现同步(Python mutiprocessing多线程池pool操作示例)
- python字符串之基本操作小练习(Python数据类型之String字符串实例详解)
- python零基础实战项目(十个Python练手的实战项目,学会这些Python就基本没问题了推荐)
- python查找含特定字符的字符串(Python实现查找字符串数组最长公共前缀示例)
- python处理所有异常(Python异常处理知识点总结)
- python复杂的验证码处理(Python 通过打码平台实现验证码的实现)
- python中的pass是干嘛的(总结python中pass的作用)
- python中如何清空列表数据(Python批量删除只保留最近几天table的代码实例)
- python为什么要用多进程(对Python的多进程锁的使用方法详解)
- python 二叉树的深度遍历(python 将有序数组转换为二叉树的方法)
- pythonindex函数用法(python sort、sort_index方法代码实例)
- python中统计一个字符出现的次数(Python统计一个字符串中每个字符出现了多少次的方法字符串转换为列表再统计)
- pythonturtle库画图代码(用Python中的turtle模块画图两只小羊方法)
- 日本菜有什么好吃(日本菜有什么好吃的做法)
- 韩国泡菜做法(韩国泡菜的做法步骤)
- 泰国旅游攻略(泰国旅游攻略必去景点)
- 越难春卷(越难春卷皮怎么用)
- 休闲VS新古典 办公家居简约设计(办公家居简约设计)
- 15个新成 园 位置公布 深圳龙岗2022年共建花园建设又有大动作(15个新成园位置公布)
热门推荐
- python零基础入门详细教程(Python零基础入门学习之输入与输出)
- idea激活服务器(搭建本地的idea激活服务器的详细教程)
- js中toFixed() 的使用
- docker容器镜像内容(Docker容器从镜像恢复代码的操作步骤)
- C#中BeginInvoke与EndInvoke
- packagejson怎么使用(最全的package.json解析)
- css 圆角卡片样式(css实现带圆角三角型的示例代码)
- sqlserver数据库备份还原(sqlserver数据库高版本备份还原为低版本的方法)
- linux基础教程磁盘配额的设计(WDCP Linux服务器磁盘爆满的处理方法)
- axios封装怎么实现(axios的简单封装以及使用实例代码)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9