Reputation: 273
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
Reputation: 29
In Python indentation is everything.
for i,v in enumerate (['item0', 'item01', 'item02']):
print (i, ":", v)
Upvotes: 0
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
Reputation: 133504
Indent is important:
for i,v in enumerate (['item0', 'item01', 'item02']):
print (i, ":", v)
0 : item0
1 : item01
2 : item02
Upvotes: 2