-5
self.test1 = input[column += 1]

Error

self.test1 = input[column += 1]
                          ^
SyntaxError: invalid syntax
Prashant
  • 710
  • 3
  • 7
  • 29

2 Answers2

1

I guess you mean one of these:

self.test1 = input[column + 1]

or

column += 1
self.test1 = input[column]

or

self.test1 = input[column]
column += 1

the column +=1 can not appear in code like what you wrote, because it doesn't have/return a value.

In C/C++ you can have that expression, but even that should be used carefully. In Python there is no operation like that.

masoud
  • 55,379
  • 16
  • 141
  • 208
  • Wanna say that `column += 1` cannot be used in this scenario either in C++, and I would assume it's the same in C. The reason is that `column += 1` is equivalent to `column = column + 1`, which doesn't make much sense to put it there. – Ranoiaetep Jun 27 '20 at 06:31
  • Instead you were probably looking for `column++` and `++column`. And like you said, those need to be used carefully since the first one is reassigning `column` after the line, and the second one is reassigning `column` first – Ranoiaetep Jun 27 '20 at 06:33
1

column += 1 can not be used in the way you are using it because it is a statement rather than an expression.

What you are writing is equivalent to self.test1 = input[column = column + 1] which doesn't much sense.

Instead you would need to do:

column += 1
self.test1 = input[column]

or

self.test1 = input[column]
column += 1

depends on which one you were looking for.


Also, since you asked in your title, ++ or -- does not exist in python.

Ranoiaetep
  • 5,872
  • 1
  • 14
  • 39