K
K
Kywaxe2020-05-28 21:19:19
Python
Kywaxe, 2020-05-28 21:19:19

How to work with parameters in the constructor?

Why in some cases in the constructor we enumerate all the parameters that are used, but in some not?
Is it due to the number of these very parameters or are there other reasons?

PS The code is taken from the vastness of the network from different resources in order to understand it.

class Person:
def __init__(self, name):
self.name = name 
self.age = 1


class Player():

def __init__(self, name):
self.id = None
self.name = name
self.type = 'Human'
self.hand = Hand()
self.legalCards = []
self.wildCards = []
self.valueChangeCards = []
self.zeroCards = []
self.canSkip = False
self.canReverse = False
self.canDrawTwo = False
self.canDrawFour = False
self.canValueChange = False
self.drew = False
self.scrollMax = 0
self.points = 0
self.forceDraw = 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Panaitov, 2020-05-28
@Picknice

If you mean the parameters of the constructor function, then they are needed to pass the input data to the object, and if you mean the registration of properties (the initial data is set), then perhaps you have already inherited some properties and let's say it makes no sense to set the initial value twice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question