Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: "can't assign to function call"

Tags:

This line in my program:

invest(initial_amount,top_company(5,year,year+1)) = subsequent_amount 

causes me to get this error:

SyntaxError: can't assign to function call 

How do I fix this and make use of value of the function call?

like image 341
Richee Chan Avatar asked May 11 '11 13:05

Richee Chan


People also ask

How do you fix SyntaxError Cannot assign to literal?

The “SyntaxError: can't assign to literal” error occurs when you try to assign a value to a literal value such as a boolean, a string, a list, or a number. To solve this error, ensure your variable names are names rather than values.

Can you assign a variable to a function call in Python?

In Python, we can assign a function to a variable. And using that variable we can call the function as many as times we want. Thereby, increasing code reusability. Simply assign a function to the desired variable but without () i.e. just with the name of the function.

How do you assign a function in Python?

The four steps to defining a function in Python are the following: Use the keyword def to declare the function and follow this up with the function name. Add parameters to the function: they should be within the parentheses of the function. End your line with a colon.

What is a syntax error in Python?

The Python SyntaxError occurs when the interpreter encounters invalid syntax in code. When Python code is executed, the interpreter parses it to convert it into bytecode. If the interpreter finds any invalid syntax during the parsing stage, a SyntaxError is thrown.


1 Answers

Syntactically, this line makes no sense:

invest(initial_amount,top_company(5,year,year+1)) = subsequent_amount 

You are attempting to assign a value to a function call, as the error says. What are you trying to accomplish? If you're trying set subsequent_amount to the value of the function call, switch the order:

subsequent_amount = invest(initial_amount,top_company(5,year,year+1)) 
like image 126
Brian Clapper Avatar answered Oct 21 '22 07:10

Brian Clapper