Python-基础-循环语句快速入门
2023-02-18 16:36:26 时间
控制循环
退出整个循环:
# 退出整个循环
break
退出当次循环:
# 退出当次循环
continue
for 循环
# -*- coding: UTF-8 -*-
# 定义一个只有单个字符的列表
source = ['A','B','C','D','E','嗨','害','嗨']
# for语句 遍历列表
# 方法一
for n in source:
print(n)
print("------------------分割-------------------")
# 方法二,如果下标是0开始,可以省略range中的0
for i in range(0, len(source)):
print(i,end='\t')
print(source[i])
print("-----------------分割----------------------")
# 方法三 循环的else用法(while循环也是一样的)
for n in source:
print(n)
else:
print("---------------循环结束-------------------")
结果:
A
B
C
D
E
嗨
害
嗨
------------------分割-------------------
0 A
1 B
2 C
3 D
4 E
5 嗨
6 害
7 嗨
-----------------分割----------------------
A
B
C
D
E
嗨
害
嗨
---------------循环结束-------------------
while 循环
# while 循环
count = 0
while count <= 100:
print("执行了:",count,"次")
count += 1
print("--------end-------------")
结果:
....
执行了: 97 次
执行了: 98 次
执行了: 99 次
执行了: 100 次
--------end-------------
相关文章
- Python模块-Requests学习与CTF和AWD实战
- [oeasy]python0033_回车_carriage_return_figlet_字体变大
- Python 命令行模块使用技巧
- python学习: fire库的使用教程
- Python 排序与查找算法收集
- Python RE 正则表达式模块
- Python Requests 实现简单网络请求
- Python 操作SQLite数据库
- Python 运用zabbix开发简易巡检工具
- 使用 Python 爬取故宫壁纸
- Python 基础知识点归纳
- Python 实现文件关键字扫描
- Python Selenium 库使用技巧
- Python 实现ARP扫描与欺骗
- Python 提取图片中的GPS信息
- Python 实现SynFlood洪水攻击
- Python 调用Zoomeye搜索接口
- Python 实现专属字典生成器
- Python PyWin32 模块
- Python 开发代码片段笔记