>> how to you declare class variables?
You mean instance variables (data members)? Like this:
Code:
class Test:
my_attr = '';
def __init__(self,message):
self.message=message
def get(self):
return self.message
Or you can just use self.message like you showed and the instance variable will spring into existence.
To define private variables, add 2 leading underscores (e.g. __myvar) and Python will mangle it into _classname__myvar. Data hiding in this case is not strictly enforced as in Java (since you can access it using '_classname__myvar' - it's more of a 'contractual agreement' basis)
>> when declaring class methods, do I always have to make the first parameter "self"? And why is it Python does this in the first place?
Consider an object x of class Test (which you defined above). Typically, from outside the class, you'd call the get() method of x like so:
What Python does is translate it into
Why the parameter is called 'self' is a matter of convention (meaning you can use something like 'pinkgoblin' instead of 'self', but it's good to follow the convention to prevent confusing others)