Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

python enumerate()

作者:屰兲洏垳&   发布日期:2025-09-11   浏览:52

# 示例代码:使用 enumerate() 函数

# enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,
# 同时列出数据和数据下标,一般用在 for 循环中。

# 示例 1: 遍历列表并获取索引和值
fruits = ['apple', 'banana', 'cherry']
for index, fruit in enumerate(fruits):
    print(f"Index {index}: {fruit}")

# 输出:
# Index 0: apple
# Index 1: banana
# Index 2: cherry

# 示例 2: 指定起始索引
for index, fruit in enumerate(fruits, start=1):
    print(f"Item {index}: {fruit}")

# 输出:
# Item 1: apple
# Item 2: banana
# Item 3: cherry

上一篇:怎样运行python程序

下一篇:python 压缩pdf

大家都在看

python时间格式

python读取文件路径

staticmethod在python中有

python开发windows应用程序

python中len是什么意思

python ord和chr

python中的yield

python自定义异常

python判断路径是否存在

python list.pop

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站