Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a8cece1

Browse files
Merge pull request #18 from vanigupta20024/master
Create enumerate.md in python
2 parents 97b3d10 + ac9b7c5 commit a8cece1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎snippets/python/enumerate.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Enumerate in Python
2+
3+
*tags:* python, enumerate
4+
5+
* `enumerate`: This function iterates through an interable object like a string or list and returns an enumerate object with associated counter starting from zero by default.
6+
7+
### Syntax:
8+
```
9+
enumerate(iter_object, counter = 0)
10+
```
11+
12+
## Snippet:
13+
14+
```
15+
# Iterable string object
16+
it_string = "hacktober"
17+
# Iterable list object
18+
it_list = ['h', 'a', 'c', 'k']
19+
20+
print(list(enumerate(it_string)))
21+
22+
# count parameter with a value of 5
23+
for val, count in enumerate(it_list, 5):
24+
print(count, val)
25+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /