Does anyone know why in the constructor (self.full = name + version ) why name + version doesn't have to be self.name + self.version?

class Robot:
-def init(self, name, version, updated):
—self.name = name
—self.version = version
—self.updated = updated
—self.full = name + version
-def introduce(self):
—print('Hello, Im ’ + self.name )

bender = Robot(“Bender”, “v2”, False)

print(bender.full)

Does anyone know why in the constructor (self.full = name + version ) why name + version doesn’t have to be self.name + self.version?

Both self.full = name + version and self.full = self.name + self.version will accomplish the same thing and result in self.full being assigned "Benderv2".

Both name and version are passed to the __init__ method when first creating an object of the Robot class, meaning that, if you define self.full inside the __init__ method, you use self.full = name + version.

However, if you defined self.full outside of the __init__ method, you would have to use self.name and self.version since name and version cannot be accessed outside of that method. Using self.full = self.name + self.version in this case also results in self.name being assigned "Benderv2". This is because self.name was assigned the value of name and self.version was assigned the value of version in the __init__ method.

Please format your code according to this post.

Welcome to the Codecademy Forums!

1 Like

In other words, since you are defining self.full in the __init__ method, you have full access to name and version so you can just write self.full = name + version.
Like @dr_victoria said, this only applies if you try to define self.full inside the __init__ method.
If you try to define it outside the __init__ method, you must write self.name and self.version, because the original name and version cannot be accessed outside of the __init__ method (hence why we saved them to the variables self.name and self.version).

1 Like

Thank you so much for your time! I understand it better and I will make sure to format it correctly next time!

1 Like