[Tutor] I'm trying to wrap my head around defs

Alan Gauld alan.gauld at btinternet.com
Tue Dec 4 23:31:25 CET 2012


On 04/12/12 21:51, frank ernest wrote:
> Opensuse 12.2 python3.2
> I'm having trouble understanding them.
> Python is my first language...   excluding English.

OK, in that case go back to basics. Don't read the reference manual, 
that's like trying to learn English by reading the Oxford English 
Dictionary. Its a great reference but its not a tutorial.

Go to the Non Programmers page and use one of the tutorials there. They 
all have slightly different styles so pick the one that looks to make 
most sense to you. Mine if you like it! :-)

> I've already read ALL OF THE PYTHON Language Referance and I still don't
> "get it."

I'm not surprised, it's designed for people who know how to program in 
Python to understand the internal details. Even the official tutorial 
assumes you already know the basic concepts of programming. That's why 
you need to go to the Non programmers page. They assume you know nothing 
beyond computer basics (how to create a text file, navigate the file 
structure and run a program).

> What do they do?
> How do they work?

The tutorials will explain.

> How do you define self?

The tutorials should explain. Dave already has, but I doubt you followed 
his explanation.

> Is self an object, a variable, or what?

Yes, its both an object and a variable. Specifically its a name that 
refers to an object. But you don't need to worry about self yet, you 
need to go back to the beginning.

> How about some over commented examples?

The tutorials should provide that.

> The if statement is a statement of comparison. what is a def and more
> specifically a class?

A def is how to define a function, which is a reusable piece of code.
A class is how to define a class which is a template for a set of objects.

But the tutorials should explain all of that.

Seriously, go through some of the tutorials. If you get stuck come back 
here with specific questions and references to the tutorial material you 
are stuck with. It may seem tedious but it is the fastest way in the 
long run.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list