[Tutor] OOP
Alan Gauld
alan.gauld at btinternet.com
Wed Apr 15 10:02:20 CEST 2009
"mbikinyi brat" <mbikinyi_brat at yahoo.com> wrote
> I am a python beginner and has never programmed
Welcome to the tutor list.
> and has been struggling to understand how to create
> objects or classes in python. Can anyone help with any
> concrete example.
Most tutorials have examples of classes and objects.
Certainly mine does. There is an example in the Raw Data
topic (with a sidebar at the end explaining it line by line)
There is also a more detailed explanatyioon in the OOP topic
in the Advanced section
Here is one example:
# define a class
class Message:
def __init__(self, msg=""):
self.text = msg
def show(self):
print self.text
# create some objects
m1 = Message("Hello world")
m2 = Message("Goodbye!")
m3 = Message()
# send the objects a message
m1.show()
m3.show()
m2.show()
> I have read most recommended textbooks but still
> have difficulties figuring what it is all about.
If you can show us an example and tell us what you don't
understand we might be able to give more specific
answers. Also please tell us which version of Python
you are using and which Operating System.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list