0

I am running this code:

count=0
l=[1,2,3]
For i in l:
  print(count+=1) 

This line throws a syntax error in line print(count+=1).

If I use like this, it works:

count=0
l=[1,2,3]
For i in l:
  count+=1
  print(count) 

What am I doing wrong here? I'm using Python 3.7

1 Answer 1

2

Having a count +=1 is the same as count = count+1, so it doesnt make sense if you type print(count = count + 1) because count is being taken as a keyword argument in print()

Sign up to request clarification or add additional context in comments.

1 Comment

@SenthilkumarM glad to help :), please feel free to select this as an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.