python - 实现带下标索引的遍历
2023-09-27 14:29:10 时间
代码如下:
#coding=utf-8
#python - 实现带下标索引的遍历.
str = 'abcdefghigklmn'
#方式一:for
i = 0
for ch in str:
print('%d\t%s'%(i,ch))
i+=1
print('-'*50)
#方式二:enumerate()
for i,ch in enumerate(str):
print i,ch
运行结果:
0 a
1 b
2 c
3 d
4 e
5 f
6 g
7 h
8 i
9 g
10 k
11 l
12 m
13 n
--------------------------------------------------
0 a
1 b
2 c
3 d
4 e
5 f
6 g
7 h
8 i
9 g
10 k
11 l
12 m
13 n
相关文章
- 多少测试人都不知道... 一行 Python 代码竟 然能实现并行
- Python递归遍历目录并删除文件中的前N行
- python json串中文乱码问题
- Python 学习笔记 - for循环: 字典遍历, 分别打印key, value, key:value
- 【华为OD机试真题 python】 二叉树层序遍历【2022 Q4 | 200分】
- python创建与遍历List二维列表
- 自学Python很简单,从入门到精通3个月就够了
- python列表用法详解(查找、添加、删除、修改、复制、循环遍历、列表嵌套)
- Python 单元测试:assertTrue 是真值,assertFalse 是假值
- python提供的多线程httpserver
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- python 遍历list并删除部分元素
- 由前序遍历和中序遍历构建二叉树-Python
- Python 用 os.walk 遍历目录
- 基于Python+MySQL编写的(WinForm)图书管理系统【100010099】
- 全网首创Python韩国女团打歌视频卡点自动混剪第1版
- python 代码库之遍历ttf字库编码和字符(含demo)
- 《Python数据科学实践指南》——2.4 流程控制
- 2022&2023华为OD机试 - 二叉树层次遍历(Python)
- odoo13 登录界面的logo显示 python 代码分析
- python:列表推导式
- python第三十一课--递归(2.遍历某个路径下面的所有内容)
- Python 遍历Sheet 每个Sheet都单独保存为一个Excel
- 使用Python爬虫爬取贴吧图片数据
- 二叉树的后序遍历(Python+C两种都有)