Set Attribute Conversion Property

An assignment statement where the target is a "get attribute" operation can be converted to a "set attribute" operation as follows:

getattr(target_1, target_2) = value = setattr(target_1, target_2, value)

The first two arguments of the "set attribute" function call is exactly the same as the "get attribute" call. The "set attribute" function also takes a third argument which is the value that we want to apply. For example:

self.first_name = first_name = self."first_name" = first_name

Here, we want to update "self.first_name" to "first_name". Try stepping through the simulator to see how LW Python executes the assignment statement.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments