[Tutor] Re: Difference between a class & module?

Gregor Lingl glingl at aon.at
Fri Jul 2 16:56:15 EDT 2004



Derek Pienaar schrieb:

>Guys thank you very much for the reply, it has certainly cleared up
>some misconceptions that was arising :-).
>
>>From Andrei and Greg's replies, I've gathered that the .join method
>is then a builtin function?
>
>I am referring to this code (version 1):
>http://www.python.g2swaroop.net/byte/ch10s02.html#first-version
>
>The .join method is used without importing any string modules ... therefore
>a builtin function?
>
>  
>
No. It's a method, which can only be called for a given string and
operates on that string, e. g.:
 >>> l=["a","b","cde","f"]
 >>> "".join(l)
'abcdef'
 >>> "---".join(l)
'a---b---cde---f'
 >>> "\n".join(l)
'a\nb\ncde\nf'
 >>> print "\n".join(l)
a
b
cde
f
 >>>

A method should be viewed as a function, which is bound to
a given object - in this case to a string object.

(You told us, that you know about classes and objects,
the "functions" you define within a class-body (which
have self as the first parameter) are called methods
of that class (or of the objects created with that class.)

Regards, Gregor

P.S.: Have a look at http://docs.python.org/lib/string-methods.html

>Many Thanks.
>
>Derek
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>



More information about the Tutor mailing list