Sep 6, 2010

Python classes

This is a basic python class.

class MyClass:
i=12345
def f(self)
return 'Hello world'

Now you can use this as like this.
MyClass.i &
MyClass.f()
These are now valid atributes and functions.

As well as this you can create an instance and ues the class llike this

x=MyClass
x.i &
x.f()
Are also now a valid atribute and a method.

Writing an __init__() to a class
MyClass:
__init__(self,read,imag)
self.r=real
self.i=imag

x=MyClass(25,90)
print x.r x.i

There are no private classes in python

No comments:

Post a Comment

Your comments are always welcome ...