SyntaxError: “can't assign to function call”

后端 未结 4 974
误落风尘
误落风尘 2020-11-30 11:33

This line in my program:

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

causes me to get this error:



        
相关标签:
4条回答
  • 2020-11-30 11:45

    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))
    
    0 讨论(0)
  • 2020-11-30 11:47

    You are assigning to a function call:

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

    which is illegal in Python. The question is, what do you want to do? What does invest() do? I suppose it returns a value, namely what you're trying to use as subsequent_amount, right?

    If so, then something like this should work:

    amount = invest(amount,top_company(5,year,year+1),year)
    
    0 讨论(0)
  • 2020-11-30 11:51

    You wrote the assignment backward: to assign a value (or an expression) to a variable you must have that variable at the left side of the assignment operator ( = in python )

    subsequent_amount = invest(initial_amount,top_company(5,year,year+1))
    
    0 讨论(0)
  • 2020-11-30 11:54

    You have done it backwards, it should be:

    amount = invest(amount,top_company(5,year,year+1),year)
    
    0 讨论(0)
提交回复
热议问题