Hello there, here is the link to the current lesson : https://www.codecademy.com/courses/learn-python-3/lessons/data-types/exercises/review?action=resume_content_item
I’m having troubles getting data from a list defined in the class.
here is the code :
class Student: testlist = [1,3,4] def __init__(self,name,year): self.name = name self.year = year self.grades =  def __repr__(self): pass def add_grade(self,grade): if type(grade) == Grade: print('Yes') self.grades.append(grade) else: print('No') class Grade: minimum_passing = 65 def __init__(self,score): if self.minimum_passing <= score: self.score = score roger = Student('Roger van der Weyden',10) sandro = Student('Sandro Botticelli',12) pieter = Student('Pieter Bruegel the Elder',8) pieter.add_grade(Grade(100)) print(pieter.grades) print(pieter.name) print(pieter.testlist)
and here are the answers :
Yes <__main__.Grade object at 0x7fa396b729b0> Pieter Bruegel the Elder [1, 3, 4]
The previous lessons talked a little about the repr method that, in this, was used to return a certain data in the class object when it was simply called.
Something like this :
class naming: def __init__(self,name): self.name = name def __repr__(self): return self.name
and in case of something like
bob = naming(bob) print(bob)
it return “bob” instead of the class object location
I searched a little on google and apparently repr can be used for alot of other things (as well as the str method), but i’m lacking knowledge to understed if that the thing i’m supposed to use (and if so, how) to get my list in the first example