[Laughing]Why the variables in the init function once again
self.What's the reason for changing it like name = name...?
self
self.in name = name
self on the left.name
is a variable called name
in the object.
self.in name = name
The name
on the right is not the name
in the object
Second parameter name
in constructor function _init__(self, name, hp, speed)
.
When declaring an object, use the constructor function
Unit("Marine", 100, 50)
I'd declare it this way
At this point, "Marine"
is passed to the second parameter name
of the constructor function _init__
. This value should be stored inside the object and handed over for the purpose of continuing to use it should be stored inside the object. To do that, self within the constructor function.name = name
to self.Declared the name variable and stored the value of the name taken over as a parameter.
© 2024 OneMinuteCode. All rights reserved.