1

I have :

a=['ab',200] 
cap_init=150

I actually want to update the value of my variable a[1] under some condition. The program can't run this instruction:

int(a[1])=int(a[1])-self.cap_init

It gives this error :

"SyntaxError: can't assign to function call"

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Newbie
  • 63
  • 1
  • 6
  • 1
    You can't use `int(something)=` (that's a function call!), just do `something=`. ;) – h4z3 Jul 24 '19 at 10:01

1 Answers1

1

When you perform int(a[1]), it just shows the integer format of a[1]. In python int() is a method to type-cast a numeric value to integer. When you are trying to do int(a[1])=... you are trying to first calculate the value int(a[1]) - self.capacite_int and then trying to assign this value to the function call of int() on the left side. If you want to change the value of a[1], you need to reassign it simply like this :

a[1] = int(a[1]) - self.cap_init
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
  • sorry i forgot to mention that a is already a list not tuple . and in both cases it doesn't work ! – Newbie Jul 24 '19 at 09:58