class Student:
def __init__(self,first,last,id):
self._first_name = first
self._last_name = last
self._id_number = id
self._enrolled_in = []
def enroll_in_course(self,course):
self._enrolled_in.append(course)
return self._enrolled_in()
s1 = Student("kathy","lor","323232")
s1.enroll_in_course("hello")
print(s1._enrolled_in)
In the code above, i am getting the error as:
Traceback (most recent call last):
File "main.py", line 14, in s1.enroll_in_course("hello") File "main.py", line 10, in enroll_in_course return self._enrolled_in() TypeError: 'list' object is not callable
I am trying to solve the error, but unable to do so. Can anybody help me here.
You have defined self._enrolled_in
but you're adding it to self.enrolled_in
Missed the underscore ( self._enrolled_in.append
)
You have called the attribute _enrolled_in
in your __init__()
method. In the enroll_in_course()
method you're trying to append to enrolled_in
which does not exist. So try by adding the underscore in front.
You are missing an _
in the appended statement. You should write self._enrolled_in.append(course)
on your enroll_in_course
method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.