Can variable definitions be done right to left?

Hi there, I’ve noticed that when I write “new_text = message.text” the code is not accepted. Whereas “message.text = new_text” is. Is this a bug, or is putting an argument on the left side of the equation and method on the right, considered incorrect syntax? Here’s what I mean:


Doesn’t work

if the syntax was incorrect, you would get a syntax error. The answer to your question can be found in understanding what self.text = new_text does.

when we create a new instance of a class:

admin = Admin("Top secret message")

we pass argument(s) to the parameter(s) of the class constructor. Then in the constructor we define instance variable (text), so we can access this instance variable in other methods:

class Admin(User):
  def edit_message(self, message, new_text):
    message.text = new_text
  def print_text(self):

admin = Admin("Top secret message")

I understand that part, but what I mean was, does the instance variable always have to be on the left side of the equation in a case like this? Or is it just a bug in the CodeCademy learning environment?

But if you understand that, the question doesn’t make much sense.

the variable you want to assign/give a value is always on the left side of the equal sign:

x = 5

On the right side of the equal sign is always the value you want to assign to the variable.

why would you want to assign an undefined instance variable to the init method parameter?

1 Like

Sorry, it’s the equals sign that was confusing me. I kept thinking if ‘a = b’ then ‘b = a’. I get what you mean now. Thanks.