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 trialmichaelangelo owildeberry
18,173 PointsWhy does my step 2 not work? =)
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.
my code is not passing: please help =)
class Student:
name = 'kenny'
def __init__():
name = kwargs.get('portlander')
8 Answers
Adam Van Antwerp
3,104 PointsFirst off, the function definition will need to be indented to python knows it is supposed to belong to the class Student.
Secondly, the __init__
will need to be passed the self object, like:
def __init__(self):
Also, if you would like to create an instance argument inside of the __init__
method, you will need so assign it to the self object's instance, like:
self.name = name_goes_here
When it is talking about using a keyword argument with a default value, that is done in the method declaration, like this:
def a_method_name(name="Default Name"):
That way, if the user doesn't pass anything in (in this instance) the value for the variable name will default to "Default Name", however the method can be called with an argument as well, and that argument will override the default value for name.
William Li
Courses Plus Student 26,868 PointsThe init method needs to have a self
, and a name
argument with default value of your choice, like this:
def __init__(self, name="kenny"):
self.name = name
César Jardim
4,847 PointsI am confused, I don't recall this being shown in the video..
michaelangelo owildeberry
18,173 PointsThank you Adam and William. =D I was misplacing code as well as using incorrect indentation. It passed =)
MUZ140082 mucheni
1,244 Pointsclass Student: name = 'innoe' def init(self): class Student: name = 'kenny' def init(name='perfie'): self.name = rupert
michaelangelo owildeberry
18,173 PointsI have read and read, helpful instruction you have passed, but I still am not getting it to pass, yet I am certain I am doing it the right way.
This what I am trying now =)
class Student: name = 'kenny' def init(name='portlander'): self.name = rupert
Samantha Nyamushamba
13,060 Pointsplease help i have tried and tried for hours whats wrong with my code class Student: name = 'sam'
def init(self, name="yolo"): self.name = name
michaelangelo owildeberry
18,173 PointsHi Samantha, how does this work? =)
class Student:
name = 'sam'
def __init__(self, name="yolo"):
self.name = name
Jon Helmus
7,312 Pointsclass Student: name= 'name goes here'
def init(self, name="pick a name"): self.name = name