user2345
user2345

Reputation: 537

Not able to increment inside an array in python

I am trying to increment the count and write the values in an array serialBuffer in Python.
How can I increment the count value (initially 0)?

 if serialIndex < 200: 
     serialBuffer[serialIndex += 1] = serialData
  # i get this error         ^ ']' expected 

Upvotes: 0

Views: 54

Answers (1)

Kevin
Kevin

Reputation: 76194

You can't do this on just one line. You'll have to split it up.

if serialIndex < 200: 
    serialBuffer[serialIndex] = serialData
    serialIndex += 1

Upvotes: 2

Related Questions