[Tutor] On understanding defintions

Steven D'Aprano steve at pearwood.info
Tue Dec 4 23:11:26 CET 2012


On 05/12/12 05:29, frank ernest wrote:
> Opensuse 12.2 python3.2
>   I discoverd that some of the examples for definitions in the
>tutorial are not valid. I am reporting this as a bug.

Don't be shy, let us know the ticket numbers :)

I've looked on the bug tracker and can't see any sign of your
bug report:

http://bugs.python.org/

But I think that before you report this as a bug, you ought to
get agreement from others that it is a bug. How about you link
to the page in the tutorial that you think is not valid, and
tell us what parts are not valid?


>   In the mean time I tried to look up definitions in the
>Language Referance part of the python documentation but I'm
>still confused. The if, for, etc. are statements of evaluation,
>comparing one item to another; so what does that make definitions?

Frank, are you a native English speaker? This is a multinational
forum and we have many people here to whom English is their second,
or third, language. It isn't clear to me whether you are having
trouble understanding the English word "definition", or whether you
don't understand some of the *specific definitions* of Python terms.

Perhaps you could try explaining your problem again, in a little
more detail.


>   What is self?

"self" is a function parameter which is automatically provided by the
Python interpreter when you call a method.

Does that help? Have you programmed using object-oriented programming
before? Do you have any previous programming experience? It is hard to
know what level of explanation you need.


>   How are definitions properly used?

I'm sorry, I don't understand your question.


>   What are the mandetory parts?

"Mandatory" means that something is compulsory, that it must be
present. For example, Python has an "if...elif...else" statement:

if x > 100:
     print("x is larger than one hundred")
elif x < 10:
     print("x is smaller than ten")
else:
     print("x is between ten and one hundred")


In this case, the "if" part is *mandatory* -- it must be there, or
you don't have an "if" statement at all. But the other two parts,
the "elif" and "else" parts, are optional.


# "elif" or "else" on its own is NOT allowed, since "if" is
# mandatory but not given. This will give a SyntaxError:
else x < 0:
     print("x is negative")


# On the other hand, "if" on its own is allowed, since the
# other parts are optional.
if x < 0:
     print("x is negative")



>   I am confused on all types of definitions not just
>functions or classes.


I'm not going to try to guess what things confuse you. Please pick
*one* concept that confuses you, one at a time, and ask about it.
We can that explain that.



-- 
Steven


More information about the Tutor mailing list