Cannot figure out line of code, also not understanding error

Chris Angelico rosuav at gmail.com
Thu Feb 20 03:54:54 EST 2014


On Thu, Feb 20, 2014 at 7:26 PM, ApathyBear <nirchernia at gmail.com> 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)

Calling a class will create a new instance of it. [1] What you do with
it afterwards is separate.

The return statement takes any value and, well, returns it. You can
return anything - an Athlete instance, the integer 13423523452, the
floating point value NaN, anything at all.

> can a similar line look like this?:
> temp1.pop(0) = Athlete(temp1.pop(0),temp1)

You can't assign to a function call, so no, you can't do that.

I recommend you start with the Python tutorial:

http://docs.python.org/3/tutorial/index.html

ChrisA


[1] The class might choose to do something different (when you call
bool with some argument, it'll return a pre-existing True or False),
but conceptually, you still get back an instance of that class.



More information about the Python-list mailing list