详解python的循环
作者:是数学系的小孩儿 时间:2022-12-29 04:22:52
目录
range函数的使用
第一种创建方式
第二种创建方式
第三种创建方式
判断指定的数有没有在当前序列中
循环结构
总结
range函数的使用
作为循环遍历的对象
第一种创建方式
r=range(10)
print(r)#range(0,10)
print(list(r))
默认从零开始,默认步长为1
range(0, 10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
第二种创建方式
指定了初始值1,到10结束,不包含10,默认步长为1
'''第二种创建方式,给了两个参数(小括号中给了两个数)'''
r=range(1,10)
print(list(r))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
第三种创建方式
最后一位数为步长
r=range(1,10,2)
print(list(r))
[1, 3, 5, 7, 9]
判断指定的数有没有在当前序列中
r=range(1,10,2)
print(10 in r)
False
循环结构
总结
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注脚本之家的更多内容!
来源:https://blog.csdn.net/qq_51082388/article/details/122180543
标签:python,循环
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
innerHTML,outerHTML,innerText,outerText用法
2008-02-15 12:22:00
msxml3.dll 错误解决办法
2009-05-25 18:02:00
数据库Oracle数据的异地的自动备份
2010-07-27 13:28:00
在php7中MongoDB实现模糊查询的方法详解
2023-09-04 12:30:00
ASP使用缓存方法及缓存类详解
2008-02-15 08:36:00
![](https://img.aspxhome.com/file/UploadPic/up/2008021512554168.gif)
python中if和elif的区别介绍
2022-07-23 14:22:10
利用PyQt5中QLabel组件实现亚克力磨砂效果
2023-12-13 18:33:04
![](https://img.aspxhome.com/file/2023/5/72125_0s.jpg)
用err.raise自定义错误信息
2008-02-20 12:48:00
浅谈Scrapy网络爬虫框架的工作原理和数据采集
2023-08-24 22:17:21
![](https://img.aspxhome.com/file/2023/0/79700_0s.jpg)
asp下过滤非法的SQL字符的函数代码
2011-03-03 11:23:00
python做图片搜索引擎并保存到本地详情
2021-08-27 01:42:33
![](https://img.aspxhome.com/file/2023/2/66842_0s.png)
服务器XMLHTTP(Server XMLHTTP in ASP)基础知识
2011-03-06 11:11:00
将Python字符串生成PDF的实例代码详解
2023-07-21 02:01:45
![](https://img.aspxhome.com/file/2023/1/88861_0s.png)
Python7个爬虫小案例详解(附源码)下篇
2023-11-23 03:47:38
![](https://img.aspxhome.com/file/2023/7/86647_0s.png)
Python Selenium 之数据驱动测试的实现
2021-12-16 22:45:27
![](https://img.aspxhome.com/file/2023/9/68259_0s.png)
大牌 Banner 设计欣赏(468x60)
2008-01-20 13:02:00
![](https://img.aspxhome.com/file/UploadPic/20081/20/2008120134648803s.gif)
如何将txt文本中的数据轻松导入MySQL表中
2009-03-06 17:35:00
DW实现鼠标滑过切换图片
2008-02-03 18:49:00
![](https://img.aspxhome.com/file/UploadPic/20082/3/200823185431657s.jpg)
详解python使用canvas实现移动并绑定键盘
2022-08-18 01:02:52
![](https://img.aspxhome.com/file/2023/8/68368_0s.png)
详解Python 使用 selenium 进行自动化测试或者协助日常工作
2023-09-05 03:44:19
![](https://img.aspxhome.com/file/2023/1/86231_0s.png)