Create an instance of a class so weird


#1

My simple code is not working which is definitely weird

class Car(object):
   my_car=Car()

#2

instances have to be created after class:

class MyClass(object):
     # content of your class here

# creating class instance
my_instance = MyClass()

classes are like blue prints (for example blue prints of a house) whereas instances are the actual thing (like the house you live in)

you don't starting building the house while still working on the blue print (which is in essence what your code is doing)


#3

Alright I did so but it is not working. I get this error.
IndentationError: expected an indented block


#4

did you read the comments in the code i posted? its says:

# content of your class here

classes can't be empty!

Its important to understand that the people on the forum help, the most important part of programming is thinking. I push you in the right direction, you need to think what the changes i suggest do


#5

Oh. You are right I added the word pass then outside the class I have created my instance and it worked thanks a lot.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.