Cannot figure out line of code, also not understanding error
Gary Herron
gary.herron at islandtraining.com
Thu Feb 20 04:04:50 EST 2014
On 02/20/2014 12:26 AM, ApathyBear wrote:
> Thanks for pointing out the missing parenthesis, it makes sense now why there was an error.
>
> I suppose my question now is (and forgive my ignorance about classes, this is my first time learning them) why is it calling Athlete with some arguments? In order to make a class object, don't you need to create an instance by assigning a class to something?
>
> like:
> x = Athlete(temp1.pop(0),temp1.pop(0),temp1)
>
> can a similar line look like this?:
> temp1.pop(0) = Athlete(temp1.pop(0),temp1)
First some notation: You are not creating a class, but rather in
instance of a class. The code
class Athlete:
...
created the class, and now you are ready to create (many?) instances
of that class.
A call like
Athlete(...)
will create an instance of that class with whatever parameters you
supply. What you do with that instance after it is created is your
choice. Assignment is one possibility, but many other operation are
also possible:
x = Athlete(...)
print( Athlete(...) )
Athlete(...)+Athlete(...) # If addition made any sense and was
implemented in the class
return Athlete(...)
...
Gary Herron
More information about the Python-list
mailing list