#100DaysOfCode in Python Transcripts
Chapter: Days 13-15: Text-based games (and classes)
Lecture: Concept: Classes
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Let's quickly review the concepts around classes
0:02
and remember that classes
0:03
are the blueprints from which we create objects
0:06
and those objects are the things that act
0:09
and take on the data of our application.
0:12
So we start by using them in the class keyword
0:14
and then we just make up a name,
0:15
this is going to be the name of the blueprint,
0:18
or the type that we create, here we called it a creature.
0:21
And then we add a dunder init,
0:24
in one of these magic methods here
0:25
and every method that is on a class
0:27
has this self message what's called
0:29
a static method or a class method
0:31
and they always have self but,
0:33
but we don't have to explicitly pass those,
0:34
Python takes care of that for us.
0:36
If we want additional premiers, they go after self,
0:38
so name and the level and we're going to assign new fields
0:43
to this by saying self.name equals name
0:45
and the new ones for self.level equals the level.
0:49
We also can add behaviors by adding additional functions,
0:52
so get_defensive_role() for example.