[Tutor] On understanding defintions

Dave Angel d at davea.name
Tue Dec 4 20:19:20 CET 2012


On 12/04/2012 01:29 PM, 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.

And what are the bug numbers?  Or links to the bug reports?  Otherwise
why are you telling us about them without mentioning any details?

>  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?

"Definitions" is an English word.  How do you mean it here?  Are you
perhaps referring to the 'def' keyword?  Or to assignment?  Or to the
'with' statement.  Or to the 'lambda' expression.

>  What is self?

'self' is a convention used in naming the special instance argument in
instance methods.  This allows a special syntax for supplying that first
argument.  'cls' is a similar convention for the class argument in class
methods.  Static methods have no special argument.  'self' is roughly
analogous to 'this used in C++ and Java, with the main difference being
that it's never implied.

>  How are definitions properly used?
>  What are the mandetory parts?
>  What are the optional parts? (in if statements the optional parts are or, and, elif, else, etc.)

'if', 'elif' and 'else' are statements.  'and' and 'or' are entirely
different;  they are operators, and have nothing to do with those three
statements.  The first two of those three statements take an expression,
which may or may not include an operator, or twenty five operators. 
Nothing special about 'and' nor 'or'  (nor '+', or '^' nor ...)

>  I also tried looking into the demos directory, I found lots of definitions but little help in understanding them.
>  I am confused on all types of definitions not just functions or classes.
>
>

Perhaps if you gave us some idea of your background, we'd have a better
idea at what level to aim our discussion.  For questions like this, I'd
personally start with the bnf for the language, if you have the
background to understand it.  I first learned bnf over 40 years ago, and
it's still useful for learning a new language.

http://docs.python.org/3.4/reference/grammar.html

On the other hand, if this is your first language, it's totally the
wrong level to start.  I had 4 under my belt before taking the compiler
design class that introduced bnf.

-- 

DaveA



More information about the Tutor mailing list