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
203,989 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
203,989 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)