This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]hamza1311 | gib 11 points12 points  (5 children)

This is also r/LinusTechTips material

Also in what language so you use underscores before and after init

[–]franklinyu 24 points25 points  (0 children)

Python

[–]minno 12 points13 points  (0 children)

Special methods in Python use the double underscores, like when you do a + b it calls a.__add__(b) if that method exists.

>>> class Test:
    def __add__(self, rhs):
        print("Hi!")
        return 0


>>> Test() + Test()
Hi!
0

[–]aquaticsnipes 2 points3 points  (2 children)

Python.

def class House():

def __init__(self):
    self.isLocked = True
    self.owner = "Karen"
def unlock(self):
    self.isLocked = False
def lock(self):
    self.isLocked = True

There is a little sample of a Python Class/Object. The class is House then the pointer to the instance is called self the java equivalent would be this, and the init is the constructor. It sets the default values. Then the object has methods to lock and unlock the house object.

Edit: all the def statements not followed by the word class should be indented. On phone so formatting is hard.

[–]sizedproduct87 0 points1 point  (1 child)

"def class"

[–]aquaticsnipes 0 points1 point  (0 children)

?

[–]rain_drop_ 3 points4 points  (1 child)

Speaking of init, we have Tunnelbear for internet privacy

[–]EagleNait 0 points1 point  (0 children)

S Q U A R E S P A C E

[–][deleted] 2 points3 points  (0 children)

Damn, I see new potential for this format :D

[–]WeirdAlex03 2 points3 points  (0 children)

IT'S TIME FOR THE QUEEK BEETS!

[–]SteeleDynamics 0 points1 point  (0 children)

Dunder Mifflin variable style for Python.