0

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)
2
  • 1
    please fix the indentation. Also, the code, properly indented, does work, please post the stacktrace and more code Commented May 10, 2013 at 10:14
  • Is this python 2.7 or python 3? Commented May 10, 2013 at 10:17

3 Answers 3

2

Indent is important:

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

0 : item0
1 : item01
2 : item02
Sign up to request clarification or add additional context in comments.

2 Comments

but the interpreter highlights the the ":" after the if-statement and generate the error message i posted
sorry I meant the for loop statement
0

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)

Comments

0

In Python indentation is everything.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.