Effective PyCharm Transcripts
Chapter: The Editor
Lecture: Object-oriented and class-based features

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's explore the object-oriented features, features for working classes and type hierarchies in PyCharm.
0:09 So over here, notice this is the code from my Python Jumpstart course which is right here, we just git cloned that in one of the earlier videos
0:17 in case you're jumping in the middle, just go here check out app seven final, that's what we're working with.
0:23 Over here we're importing a couple of classes a Wizard, a Creature, a Small Animal and a Dragon, and we'll go check this out in a second
0:32 but the creature is the base type and then we have a Small Animal and a Dragon, both deriving from Creature and then Wizard as well.
0:41 So let's go over to this actors thing we can use double search or so, just hit A and look, there's actors right there,
0:50 obviously, it's small enough we could click over and find it but notice, we have this type hierarchy, here we've got our Creature
0:57 the Creature is kind of the base type and it implicitly inherits from object in Python 3, it's as if we wrote this,
1:05 but we don't have to because it's Python 3, so down here we have things like the __init__ and notice this is saying that this is overwriting
1:17 or is overwritten in Dragon for example among other places. This class is derived from by Wizard, Small Animal and Dragon,
1:27 that's pretty super cool, right, and this is part of the Python data model, this actually comes from objects we're overwriting this from object.
1:37 Now, here, this get defensive roll this is itself overwritten somewhere else so let's play the game real quick,
1:46 now remember, we could just click here and run it but I'll show you one other way to run our code
1:51 just because sometimes this has console colors and whatnot and you just want it in a proper terminal
1:57 so I could do this copy, copy path open this up, clear that out we'll just say Python 3 and boom, there it goes,
2:06 well I guess it doesn't have console colors but that's all fine. So what we could do is we could look around
2:10 and we could see that there is a Toad of a certain level, a Tiger, a Dragon, an Evil Wizard
2:16 and then we could say I would like to attack the Bat of level 3 that has appeared from the dark and foggy forest.
2:22 The Wizard has handily triumphed over the Bat, now a Tiger a is here, we could attack it, a Dragon— we've been defeated and so on.
2:30 The idea is we play this game, it's very simple but you basically have these attacks that the Wizard can do
2:36 and all the creatures can have a defensive roll, some of them like we have over here the Small Animal and the Dragon have different types of defense
2:46 than the standard Creature, well, we can use this to discover information about the type but we can also use this to navigate,
2:54 so watch this, if I want to go over here to where this is all written by Dragon I click,
2:58 boom, I'm in the Dragons __init__ where it's overwriting the Creatures and then, of course, we are doing this super here.
3:05 We're also capturing whether the Dragon breathes fire, capturing its level of scaliness, things like this.
3:11 This works in reverse too, get defensive roll, that says this is overwritten from Creature, click on that, it takes us back to Creature.
3:18 It even, and so much as we can understand information about the standard library works there as well
3:25 so this will take us to the representation method in object but because it's implemented in C you don't know so much,
3:34 not all of the standard libraries implemented in C though and if there was some piece that was written in Python
3:39 it would take us straight to that and that would be awesome. So you can see whenever we're working with these type hierarchies,
3:43 we get nice little tips about what we're doing and this can let you know like should you call things like the super base method or not.
3:53 So here the small Creature is like half as defensive as a standard Creature because it's small and wimpy, right
3:59 that's kind of what this implementation says. For the Dragon, there's a bunch of different modifiers that we can have here,
4:06 we tried a few attempts in the course that actually wrote this code to come up with it and talk about some of the expressions here
4:12 but basically, whether you're scaly, whether you breathe fire these affect how defensive you can be as a Dragon.
4:19 You can see they are pretty tough to beat a scaly fire-breathing Dragon is super hard to beat in this game.
4:24 But, hopefully, that gives you a good sense of some of the objects or features the other things that you can notice maybe is if I type self.
4:31 I get Dragon features as autocomplete, I get Creature features from the base type, and I get object features,
4:40 so you immediately get things like autocomplete throughout the type hierarchy as well— pretty awesome.


Talk Python's Mastodon Michael Kennedy's Mastodon