FAQ: Learn Python: Classes - Methods

#1

This community-built FAQ covers the “Methods” exercise from the lesson “Learn Python: Classes”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

FAQs on the exercise Methods

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

#2

I am having a problem with the compiler with this exercise. The very first step gives me the error: “SyntaxError: unexpected EOF while parsing” with the code:

class Rules:

I checked and its the exact same as the solution given by codecademy (not much difficulty in this very first step…)

Any ideas on why?
THanks!

#3

i had the same problem.
i think the reason why is because just wrighting the class is not the right proper syntaxt.
an class alawys needs to be defined. if you want to define an empty class you should use.

class Rules:
pass

and then later when you continue the code you can get rid of pass that is how i did it

#4

i dont understand why in the example is:
class Dog():
dog_time_dilation = 7

and in the excersise is:
class Rules:

with out (), whats the difference?, i was using parentesis, as class Rules(): and i ve got the error metioned : “SyntaxError: unexpected EOF while parsing”

#5

All the Python 3 documentation I’ve read does not include parens on class definitions, although Python 2 used to include class Foo(object) and both require parens on derived classes for obvious reasons.

class Rules:
    pass

We must include at least pass for the syntax to be complete at this stage. Just a signature line is not enough and will raise a syntax error. The Shell will not let us return to the command prompt if we haven’t added the pass line.

Bottom line, until someone pipes in with better information, it doesn’t seem to make any difference. The convention is to not use them, so that would be the preferable option, as I see it.

1 Like
#6

thanks for the answer, i was confused on when to use them, :slight_smile:

i think the parentesis are the error, maybe the example of codeacademy is incorrect??

1 Like
#7

I cannot produce any errors with or without the parens on the definition line.Going forward it might be best to not use them.

1 Like