Перейти к содержимому

Give Me 13 Minutes, I'll Make Python Classes Click (self, Inheritance, super, Polymorphism)

Math Unlocked

0:00 / 0:00

Give Me 13 Minutes, I'll Make Python Classes Click (self, Inheritance, super, Polymorphism)

11 просмотров · 6 дн. назад
Math Unlocked
90 подписчиков
11 просмотров · 6 дн. назад
A private balance that Python says does not exist, and then prints anyway. Learn Python classes from scratch: objects, _init_ and self, methods, changing and deleting properties, a bank account class, inheritance, super(), polymorphism, duck typing, encapsulation, properties with setters and name mangling, all run live in Jupyter. This is Lesson 25 of Python for AI and Data, a free course from your first install all the way to NumPy, pandas, charts and machine learning. Chapters 0:00 Private balance, read anyway 0:28 Classes and objects 1:04 _init_ and self 1:52 Missing argument error 2:07 Methods 2:31 What self really is 3:13 Changing properties 3:48 Deleting properties and objects 4:14 Methods that change objects 4:52 Bank account class 6:07 Inheritance 7:12 Multi level inheritance and MRO 7:41 The missing super trap 8:02 super() 8:35 Polymorphism 9:24 Duck typing 9:56 Encapsulation and properties 10:52 Property setters 11:24 Name mangling 12:09 Recap 12:52 Next lesson Code from this lesson class Dog: def __init__(self, name, age): self.name = name self.age = age def bark(self): return f"{self.name} says woof" class Puppy(Dog): ... super().__init__(name) @property def balance(self): return self.__balance acc._BankAccount__balance Errors you will meet TypeError: Dog.__init__() missing 1 required positional argument: 'age' TypeError: Cat.meow() takes 0 positional arguments but 1 was given AttributeError: 'Dog' object has no attribute 'name' Free practice notebook and written notes for every lesson https://whop.com/selwyn-builds/ New to Python? Start with Lesson 0 on the Math Unlocked channel. Next on Python for AI and Data, classes part 3, class variables and dunder methods. Music "Echoes of Time v2" by Kevin MacLeod (incompetech.com) Licensed under Creative Commons, By Attribution 4.0 License http://creativecommons.org/licenses/b... #python #pythontutorial #learnpython #coding #jupyter