Class Basics - How is it wrong!


#1

The instructions say to 'Define a new class named "Car". For now, since we have to put something inside the class, use the pass keyword.'

My code for this is:

class "Car"(pass):

Can anyone tell me what is wrong? :worried:


#2

I would search for examples of creating a class in Python, possibly throwing in "pass" or "empty" in the query if I was looking to make one with no methods or otherwise in it. What you wrote is quite far off (as opposed to a subtle difference) so simply comparing to an example should answer your question.


#3

I looked back on previous exercises and it turns out pass cannot be an argument. It has to be inside the class. I also found out that the argument that has to be called 'object'.


#4

Even more fundamental than that, pass is a statement, you might as well have put an if-statement in there.
In python2 your classes should inherit from object in order to use the new-style classes. (They changed the object model but were required to stay backwards compatible) In python3 they were able to drop backwards compatibility and all classes inherit object implicitly.


#5

same here, i am stuck in this lesson.. i have tried to make the class Car(object):

class Car(pass):

class Car():

none of them works..

it is displaying error:
class Car(object):
^
SyntaxError: unexpected EOF while parsing

no clue whats wrong... some help will be appreciated,


#6

Finally, got the answer.... just enter the following code in the area and the lesson will be cleared.
class Car(object):
pass


#7

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