How to iterate by sequence index in Python?


Sequence objects in Python are an ordered collection of items. Each item in the sequence (list, tuple and string) is accessible by index starting with 0.

To traverse elements in a list

>>> L1=[10,20,30,40,50]
>>> for i in range(len(L1)):
print (L1[i])

10
20
30
40
50

To slice one character at a time out of a string

>>> string ='TutorialsPoint'
>>> for i in range(len(string)):
print (string[i])

T
u
t
o
r
i
a
l
s
P
o
i
n
t

Updated on: 26-Feb-2020

338 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements