
Explore object oriented programming in Python through a Harry Potter themed narrative that makes relearning OOP engaging. Empower your understanding of Python's OOP concepts with a lighthearted yet serious approach.
Embark on a seven-year Hogwarts-style tour of object oriented programming in Python, from the OOP mindset to defining classes, attributes, methods, object interactions, inheritance, and dunder, class, and static methods.
Learn how programming stores data and acts on it, and how object oriented programming unites data with doing stuff with data as objects in Python, with lists and append.
Learn how in Python everything is an object, and how to use classes as templates to create custom data types and objects that solve real coding problems.
Explore how Python object usage differs from deeper object oriented programming, and learn to balance classes and objects with a pragmatic mindset using the muggles, purebloods, and pragmatists analogy.
Explore object-oriented programming terms in Python, including class as a template and object as an instance, and learn how data and methods live in each object.
Create a wizard class in Python to model Hogwarts interactions, linking professors, students, subjects, wands, and spells through object-oriented programming.
Explore how the __init__ method initializes class instances and defines data attributes such as name, patronus, birth, house, and wand, turning a class into a template.
Create two wizard objects from a wizard class to illustrate that separate instances share a template yet store distinct data in attributes like name, wand, house, birth year, and patronus.
master special methods in Python, including the dunder init, and see how these methods set initial values for each instance.
Explore how instance variables attach to objects to differentiate wizard instances, and learn why we avoid direct data attribute assignment in favor of initialization and methods.
Explore how self acts as a placeholder for an object in a class, linking parameters to the data attribute name and showing Harry and Hermione relate to the object's name.
Learn how the __init__ method initializes a Python object, how calling a class creates an instance, and how self accesses per-object data like name, patronus, and birthyear.
Build your understanding of object-oriented programming in Python by exploring key terms like method, special method, init, instance, and self, and learn how dunder or magic methods govern object behavior.
Learn to define a wizard class in Python, implement the init method to set data attributes, and use a method to assign a wand, updating the object's state with self.
Explore how the self parameter acts as the object in Python methods, and watch Hermione and Harry receive wands via assign wand, dragon heartstring, 10.5in, with prints showing the results.
Explore object-oriented programming in Python by defining a House class with an init method, attributes like name, founder, colors, animal, and a members list to manage points at Hogwarts.
Define a house class with attributes like name, founder, colors, animals, members, and points. Provide methods to add or remove members, update total points, and get house details using self.
Link the wizard to a house by assigning a house object to the wizard, and update the house's members using its add member method, highlighting self as the wizard instance.
Initialize a house class with required init parameters, assign Harry to Gryffindor, and maintain a unique members list to avoid duplicates.
Create a wand class in Python by defining an __init__ with wood, core, and length attributes, and plan for casting spells and cost. Instantiate a wand and preview its printing.
Define instance methods and self as the first parameter, and note that the instance is automatically passed. Note that some methods belong to the class, not to any specific instance.
Explore how wizard, house, wand, and spell objects interact in Python, using init data attributes and methods, with a wand casting spells based on a random success check.
Learn object-oriented programming in Python by modeling wizard and wand classes, implementing cast spell logic, and tracking spell effects, wand checks, and wizard skill growth.
Explore how to pass a wizard’s skill to a wand’s cast spell method, linking three objects—wizard, wand, and spell—and coordinate their interactions in Python.
Update wand.cast_spell to accept a wizard and add wand power with default 0.5; adapt spell.is_successful to use wand power and wizard skill, showing data flow across wand, spell, and wizard.
Explore object interactions in Python by modeling wizard, wand, and spell as collaborating objects where cast spell methods pass data to determine success, influenced by spell difficulty, wand, and wizard.
Explore inheritance in python by modeling professors and students as subclasses of a wizard, with subject taught for professors and subjects learned for students, avoiding duplicate code.
Create a professor class that inherits from wizard, initialize with name, Patronus, birth, and subject using super(), and verify inheritance through instance checks and subject taught access.
Learn how a professor subclass extends the wizard class by adding a subject attribute and a higher starting skill, overrides assign_house with a head_of_house option, and introduces assess_student.
This lecture defines a student class that inherits from Wizard, adds school year and subject grades initialized to none, and implements assign subjects, take exam, and Sorting Hat house assignment.
Execute cross-class checks in Python by implementing professor.assess_student to verify a student's subject, print results, and trigger take_exam, illustrating data flow between student and professor objects.
Explore object-oriented programming by building and testing new classes, including students, professors, houses, and interactions in a Hogwarts-themed example; understand inheritance, methods, and simple testing workflows.
Explore object-oriented terminology in Python, defining superclass, base class, and parent class alongside subclass, derived class, and child class, and explain how inheritance and the super function work.
Dive into Python's special methods and learn how to define object comparisons, like why Hermione and Draco can't be compared without a custom __gt__ method.
Define the __gt__ dunder method to compare wizard objects by skill, using inheritance so all wizards share it, with two arguments and a boolean return, used by Python for >.
Define wizard object equality with __eq__ based on name, patronus, and birth year, and contrast with Python's is and ==, especially when __eq__ is absent.
Implement __iter__ to make your class iterable by returning an iterator from its members. Then iterate Gryffindor in a for loop to view its three members.
Define the __str__ method to provide a user-friendly string when printing objects. Override it in subclasses like student to show name, house, and year; wizard uses the default.
Explore how __repr__ and __str__ differ as dunder representations, craft a developer-friendly repr that can recreate objects, and distinguish user-friendly prints from wrapper outputs.
Explore how Python's special methods control object behavior, including init, greater than, equals, iteration, and string representation, with a preview of less common topics for year seven.
Explore how objects and instances differ in object oriented programming, then see how a random Sorting Hat assignment exposes flaws when each student creates its own house object.
Move house definitions out of the method, pass a houses list to sorting hat, ensuring one Gryffindor house and one of each house to be reused across the code.
Demonstrates using a class attribute to store houses as a dictionary, and defines class methods like get_house and get_house_names to access shared data from the class.
Finish the third attempt by using Hogwarts class methods to assign a house with the Sorting Hat, selecting a house name from get_house_names and retrieving the house with get_house.
Explore instance, class, and static methods in a Python wand class, including self-based access, class attributes like houses, and a static method to convert centimeters to inches for international wizards.
Explore how instance, class, and static methods differ, with class methods bound to the class and instance methods accessing the instance state, while special methods are mostly instance methods.
Explore object-oriented programming in Python through wizard and professor examples, covering classes, data attributes, methods, object interactions, inheritance, and special methods, including class and static methods.
This course covers Object-Oriented Programming in Python using a different approach. It's a tour of object-oriented programming (OOP) through a Harry Potter-themed extended example.
Welcome to Hogwarts School of Codecraft and Algorithmancy!
The course covers:
OOP fundamentals and mindset—what's different about OOP and why do we need it?
Creating classes, defining `.__init__()` and understanding what it does, and creating data attributes
Defining methods to give objects the ability to do stuff
Interaction between different classes
Inheritance in OOP
Special methods, also known as dunder methods
Class attributes and class methods
It's not your usual OOP course…
---
About me, your instructor
I've been teaching Python for a decade. Before that, I worked as a physicist and used programming in my research work for over a decade.
My focus is on communicating clearly, in a friendly and relaxed manner. I'm the author of the The Python Coding Book (you can ask Google for a "python book" and you'll find this book as one of the first entries) and I have taught Python to individuals and corporations around the world.
And I'm approachable. You can ask me questions and I'll always reply, whether here on social media or anywhere else you can find me!