Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python (retired) Objects __init__

luke hammer
luke hammer
25,513 Points

mental check

I"m must be missing something here. i test this code other places and it seems that the test is not correct can some one tell me what is going on here??

student.py
class Student:
  def __init__(self,name):
    self.name = name
luke hammer
luke hammer
25,513 Points

this is the tasks Override init in Student. Give init a name keyword argument with a default value of your choice. Set self.name equal to the name argument.

3 Answers

Chase Swanson
PLUS
Chase Swanson
Courses Plus Student 8,886 Points

When you define a method with parameters you may set default values for them.

For example..

def methodName(foo, bar = "example"):

With this, if you call the method and only pass one parameter, it will set the second parameter to the default value.

You need to do the same thing in this exercise. It wants you to set a default value for name in the dunder init method.

As I mentioned before, your code as it is written is technically correct, but the drill is looking for you to set a default value as well.

Chase Swanson
PLUS
Chase Swanson
Courses Plus Student 8,886 Points

Your code is technically fine but the drill wants you to set a default value for name in init. If you do that it should pass.

luke hammer
luke hammer
25,513 Points

I'm sorry I don't understand your answer. aren't I over writing the default init??

class Student: def init(self, name="kiran"): self.name = name