Some problem here,also in basic understanding concepts of class(oop).
Don't use
If think of it so should information about instrument come in from outside,and not be hard coded in class.
This way can eg all band members can use same class.
Don't use
type
word as it used bye Python.If think of it so should information about instrument come in from outside,and not be hard coded in class.
This way can eg all band members can use same class.
class Instrument: def __init__(self, instrument): self.instrument = instrument def description(self): return f'My instrument is {self.instrument}'Usage:
>>> player_1 = Instrument('Gutiar') >>> player_2 = Instrument('Drums') >>> player_1.instrument 'Gutiar' >>> player_2.instrument 'Drums' >>> >>> player_1.description() 'My instrument is Gutiar' >>> player_2.description() 'My instrument is Drums'A quick look a at
__str__
and __repr__
,which is useful many times to have in a class.__str__
could replace description()
method.class Instrument: def __init__(self, instrument): self.instrument = instrument def __str__(self): return f'My instrument is {self.instrument}' def __repr__(self): return f'Instrument({self.instrument!r})'Usage:
>>> player_1 = Instrument('Gutiar') >>> player_2 = Instrument('Drums') >>> >>> # print call __str__ >>> print(player_1) My instrument is Gutiar >>> >>> # only object show __repr__ >>> player_2 Instrument('Drums')