Amr Bakri
Amr Bakri

Reputation: 273

Invalid Syntax, when running for loop

I was practising some exercises in Python. And Python interpreter has generated error saying: Invalid Syntax when I tried to run the below posted code:

Python code:

#Use of Enumerate:
for i,v in enumerate (['item0', 'item01', 'item02']) :
    print (i, ":", v)

Upvotes: 0

Views: 134

Answers (3)

cachorrocadi
cachorrocadi

Reputation: 29

In Python indentation is everything.

for i,v in enumerate (['item0', 'item01', 'item02']):
    print (i, ":", v)

Upvotes: 0

Ravi Pal
Ravi Pal

Reputation: 395

You have not given space for print statement you can check Python: Myths about Indentation

for i,v in enumerate (['item0', 'item01', 'item02']):
    print (i, ":", v)

Upvotes: 0

jamylak
jamylak

Reputation: 133504

Indent is important:

for i,v in enumerate (['item0', 'item01', 'item02']):
    print (i, ":", v)

0 : item0
1 : item01
2 : item02

Upvotes: 2

Related Questions