Skip to content

Commit 9a83c0d

Browse files
author
ashegde
committed
feat(example): iterator
1 parent 95c7d8b commit 9a83c0d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

codes/session_2/iterators.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Open terminal > python3 iterators.py
2+
# Start typing below commands and see the output
3+
4+
for element in [1, 2, 3]:
5+
print(element)
6+
7+
for element in (1, 2, 3):
8+
print(element)
9+
10+
for key in { 'one': 1, 'two': 2, 'three': 3}:
11+
print(key)
12+
13+
for char in '123':
14+
print(char)
15+
16+
print('\n\n')
17+
18+
s = 'XYZ'
19+
it = iter(s)
20+
print(next(it))
21+
print(next(it))
22+
print(next(it))
23+
print(next(it)) # StopIteration Exception

0 commit comments

Comments
 (0)