I would like to understand Python classes and objects.
I am trying and struggling to get the output results from inner-class, Features.
class Person:
def __init__(self):
pass
def first_name(self, first_name ):
self.first_name = first_name
return self.first_name
def middle_name(self, middle_name):
self.middle_name = middle_name
def last_name(self, last_name):
self.last_name = last_name
return self.last_name
class Features:
def __init__(self):
pass
def color(self, color):
self.color = color
return self.color
x = Person()
print(x.last_name('Jimmy'))
print(x.Features.color('Brown'))
Instead I get this error:
TypeError: Person.Features.color() missing 1 required positional argument: 'color'
How can I do this correctly?
self._colorto signify that you're referring to a private member, and not the method again.Featuresclass at module level, and add an instance of it to yourPersonclass in its__init__method. Frameworks do sometimes use nested classes, but that is for the namespace, not for using those as "classes".