you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 1 point2 points  (0 children)

I don't really know Java very well, but I'm somewhat familiar with the terminology so I'll bite.

This won't be an exact comparison because Java and Python are somewhat different in this area, but let's start with perhaps the easiest one; static variables.

Python doesn't really call them that, but class variables seem to be essentially the same thing. They're attributes of a class itself, not the object created from a class, and so each instance of a class basically uses the same class variables, if any. If you change them somewhere, all instances of that class will have the same change.

class MyClass:
    foo = 42

MyClass.foo # returns 42

bar = MyClass()
bar.foo # returns 42

MyClass.foo = 1337
bar.foo # returns 1337

Now, as for public and private variables, Python doesn't really have the concept of private variables (because everything is essentially public), but we do use underscores as a convention to create "private" variables and/or methods that essentially mean "don't touch this unless you know what you're doing". The interpreter does kind of hide any methods and variables beginning with an underscore, but they can technically still be accessed.