Python Forum
Python Classes - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python Classes (/thread-22786.html)



Python Classes - leodavinci1990 - Nov-27-2019

from random import Random # library for randoms
class Die(object): # define the class
    sides = [1,2,3,4,5,6]
    def __init__(self): # METHOD
        self.sideShowing = Die.sides[0] # PROPERTY
    def roll(self): # METHOD
        newSide = Random().choice(Die.sides)
        self.sideShowing = newSide # PROPERTY
1.Why is there an object in parentheses at the class definition (line 1) ? what is this object and why is it passed as an argument-is it a special type of argument or just the name of an argument?

2.What is the self in parentheses at lines 4 and 7?

3.What is the _init_ method?


RE: Python Classes - buran - Nov-27-2019

I would suggest to check 2 of our class tutorials:
Class basics
Class: inheritance