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

Why is this code failing

Challenge task 2 of 2 and the error is it can't find 'Student'.My code is attached :)

first_class.py
class Student:
    name = 'Aizah'
    Student('me')
    print(name)

4 Answers

Steven Parker
Steven Parker
231,198 Points

The code after the class should not be indented. Also, you may want to review the syntax for creating an instance and accessing attributes. Creating an instance will require the assignment operator ("_"), and accessing an attribute will use the membership operator (".").


UPDATE: - the (task 2) code after the class is still indented

  • there is still no creation of the variable "me" and assignment with a new class instance
  • there is still no reference to the class in the "print", and no membership operator
  • plus now, the class name is being referred to as "Student_me" instead of "Student"

You might want to review the video, and take another look at the examples in it.

Steven Parker
Steven Parker
231,198 Points

Another update:

  • line 2 does need to be indented, it's part of the class
  • line 3 needs parentheses after the class name to create a new instance
  • line 4 should reference the instance name instead of the class itself
class Student:
    name = 'Aizah'
    Student_me()
    print(name) 

it is still not running

ok, thank you

Sorry to bother you but where am I going wrong now

class Student:
name = 'Aizah'
me = Student
print(Student.name)