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"

1
  • 1
    You can't use int(something)= (that's a function call!), just do something=. ;) Commented Jul 24, 2019 at 10:01

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

sorry i forgot to mention that a is already a list not tuple . and in both cases it doesn't work !

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.