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 Instant Objects Your first class

Challenge Task 2 of 2 make an instance of your class named me. Then print() out the name attribute .Does not work

I really don't understand why this is not working, I am fed up with this! Please anyone can check this example it is the second part of the first challenge in the object oriented course/Python :

Challenge Task 2 of 2

Great work! Now, make an instance of your class named me. Then print() out the name attribute of your instance.

first_class.py
Class Student:
    name = "something"

me = Student
print(me.name)

class instead of Class.

>>> Class Student:
  File "<stdin>", line 1
    Class Student:
                ^
SyntaxError: invalid syntax

>>> class Student:
...   name = "blah"
...
>>> me = Student
>>> me.name
'blah'
>>>

4 Answers

Ryan Sands
Ryan Sands
4,543 Points

actually it should be......

class Student:
     name = "something"

me = Student()
print(me.name)

when making an instance of a class you must add those parentheses after so it can be an instance, otherwise its not. this passed for me! Good luck, Keep on coding!

[MOD: added ```python formatting -cf]

Why did you use Student()?

Hi, This is my code: class Student: name = 'Jack' me = Student print(me.name)

But...., I still cannot get the right output. Can u all tell me why?

luther wardle
seal-mask
.a{fill-rule:evenodd;}techdegree
luther wardle
Full Stack JavaScript Techdegree Student 18,029 Points

This worked for me, I had the same code but forgot not to indent the code that's creating an instance of the class lol, so thank you!

Andrei Cordis
Andrei Cordis
Courses Plus Student 4,442 Points

Why indentation is not necessary in the last line (the print line) ?

yes, it works

it does not work bro

oh sorry it works