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

Francois Dion francois.dion at gmail.com
Tue Dec 4 23:21:23 CET 2012


On Tue, Dec 4, 2012 at 4:51 PM, frank ernest <doark at mail.com> wrote:
> Opensuse 12.2 python3.2
> I'm having trouble understanding them.
> Python is my first language...   excluding English.
> I've already read ALL OF THE PYTHON Language Referance and I still don't
> "get it."
> What do they do?

Let's start simple. It is a Python keyword to define a function.

> How do they work?

Just like a function in mathematics, they take some arguments, do
stuff with it (hopefully) and more than likely return something. For
example, cos(angle) defines the cosinus calculation for a given angle.
This function is an object that has been defined at some point by a
def cos(angle):

So there is a difference between *def*ining a function and using it,
hence the def keyword.

> How do you define self?

You do not. It is related to scope,

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

You really need to understand functions first, then scope, then we can
talk class.

So, my question to you before we get too far, are you ok with the
concept of mathematical functions?

Francois

--
www.pyptug.org  -  raspberry-python.blogspot.com


More information about the Tutor mailing list