DEV Community

qing
qing

Posted on • Edited on

Master `enumerate()` in 1 Line

TIL: enumerate() has a start parameter you probably never used

When working with loops in Python, enumerate() is a lifesaver. It allows us to loop over a list (or other iterable) and have an automatic counter/index along with it. But, did you know that enumerate() has a start parameter that lets you specify the starting index?

By default, enumerate() starts counting from 0, which is usually what we want. However, sometimes we need to start from a different number, like 1. That's where the start parameter comes in.

Here's a comparison of the default enumerate() behavior vs using the start parameter:


python
fruits =

---

*Follow me on Dev.to for daily Python tips and quick guides!*

---

If you found this useful, you might like **[Python Automation Scripts Pack (10 Ready-to-Use Tools)](https://qssec.gumroad.com/l/python-automation-pack)** — a practical resource that takes things a step further. At $14.99 it's a solid investment for your toolkit.

---
喜欢这篇文章?关注获取更多Python自动化内容!
Enter fullscreen mode Exit fullscreen mode

Top comments (0)