|
| https://realpython.com/ |
| Start Here | https://realpython.com/start-here/ |
|
Learn Python
| https://realpython.com/lessons/python-class-object-summary/ |
| Python Tutorials →In-depth articles and video courses | https://realpython.com/search?kind=article&kind=course&order=newest |
| Learning Paths →Guided study plans for accelerated learning | https://realpython.com/learning-paths/ |
| Quizzes & Exercises →Check your learning progress | https://realpython.com/quizzes/ |
| Browse Topics →Focus on a specific area or skill level | https://realpython.com/tutorials/all/ |
| Community Chat →Learn with other Pythonistas | https://realpython.com/community/ |
| Office Hours →Live Q&A calls with Python experts | https://realpython.com/office-hours/ |
| Podcast →Hear what’s new in the world of Python | https://realpython.com/podcasts/rpp/ |
| Books →Round out your knowledge and learn offline | https://realpython.com/products/books/ |
| Reference →Concise definitions for common Python terms | https://realpython.com/ref/ |
| Code Mentor →BetaPersonalized code assistance & learning tools | https://realpython.com/mentor/ |
| Unlock All Content → | https://realpython.com/account/join/ |
|
More
| https://realpython.com/lessons/python-class-object-summary/ |
| Learner Stories | https://realpython.com/learner-stories/ |
| Python Newsletter | https://realpython.com/newsletter/ |
| Python Job Board | https://www.pythonjobshq.com |
| Meet the Team | https://realpython.com/team/ |
| Become a Tutorial Writer | https://realpython.com/write-for-us/ |
| Become a Video Instructor | https://realpython.com/become-an-instructor/ |
| Search | https://realpython.com/search |
| https://realpython.com/search |
| Join | https://realpython.com/account/join/ |
| Sign‑In | https://realpython.com/account/login/?next=%2Flessons%2Fpython-class-object-summary%2F |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-class-object |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-class-object |
| https://realpython.com/courses/python-class-object/#team |
| Class Concepts: Object-Oriented Programming in Python | https://realpython.com/courses/python-class-object/ |
| Christopher Trudeau | https://realpython.com/courses/python-class-object/#team |
| Recommended Tutorial | https://realpython.com/python-classes/ |
| Course Slides (.pdf) | https://realpython.com/courses/python-class-object/downloads/python-class-object-slides/ |
| Sample Code (.zip) | https://realpython.com/courses/python-class-object/downloads/python-class-object-code/ |
| Ask a Question | https://realpython.com/lessons/python-class-object-summary/#discussion |
| https://realpython.com/feedback/survey/course/python-class-object/liked/?from=lesson-title |
| https://realpython.com/feedback/survey/course/python-class-object/disliked/?from=lesson-title |
| Contents | https://realpython.com/lessons/python-class-object-summary/#description |
| Transcript | https://realpython.com/lessons/python-class-object-summary/#transcript |
| Discussion (12) | https://realpython.com/lessons/python-class-object-summary/#discussion |
| Object-Oriented Programming (OOP) With Python | https://realpython.com/learning-paths/object-oriented-programming-oop-python/ |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson_preview&utm_content=python-class-object |
| Sign-In | https://realpython.com/account/login/ |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson_preview&utm_content=python-class-object |
| Sign-In | https://realpython.com/account/login/ |
| 00:00 | https://realpython.com/lessons/python-class-object-summary/#t=0.56 |
| In the previous lesson, I showed you all of the things you’ve learned so far in | https://realpython.com/lessons/python-class-object-summary/#t=0.56 |
| one coding example. | https://realpython.com/lessons/python-class-object-summary/#t=4.66 |
| This lesson wraps up part one of the course and summarizes what you’ve learned. | https://realpython.com/lessons/python-class-object-summary/#t=6.37 |
| 00:11 | https://realpython.com/lessons/python-class-object-summary/#t=11.69 |
| A structure that contains data and operations in Python is defined using the | https://realpython.com/lessons/python-class-object-summary/#t=11.69 |
| class keyword. And once you have a class, | https://realpython.com/lessons/python-class-object-summary/#t=15.65 |
| you instantiate it to create an instance of the class called an object. | https://realpython.com/lessons/python-class-object-summary/#t=18.63 |
| 00:23 | https://realpython.com/lessons/python-class-object-summary/#t=23.68 |
| Each object has its own attributes and a reference to each method defined in | https://realpython.com/lessons/python-class-object-summary/#t=23.68 |
| the class. | https://realpython.com/lessons/python-class-object-summary/#t=28.05 |
| The first method you learned about was the special one known as .__init__(). | https://realpython.com/lessons/python-class-object-summary/#t=29.47 |
| 00:33 | https://realpython.com/lessons/python-class-object-summary/#t=33.8 |
| This method is called after the object is created and is used to initialize its | https://realpython.com/lessons/python-class-object-summary/#t=33.8 |
| contents. For most classes, | https://realpython.com/lessons/python-class-object-summary/#t=38.17 |
| you’ll override the .__init__() method for your own purposes. | https://realpython.com/lessons/python-class-object-summary/#t=40.19 |
| 00:44 | https://realpython.com/lessons/python-class-object-summary/#t=44.61 |
| Like all methods, the first argument to .__init__() is self, | https://realpython.com/lessons/python-class-object-summary/#t=44.61 |
| which when the method is called | https://realpython.com/lessons/python-class-object-summary/#t=48.83 |
| contains a reference to the newly constructed object. | https://realpython.com/lessons/python-class-object-summary/#t=50.38 |
| 00:53 | https://realpython.com/lessons/python-class-object-summary/#t=53.88 |
| You can assign attributes to the object using dot notation. | https://realpython.com/lessons/python-class-object-summary/#t=53.88 |
| When you do this in .__init__() or any other method, | https://realpython.com/lessons/python-class-object-summary/#t=58.45 |
| you access the object instance through the self argument. For example, | https://realpython.com/lessons/python-class-object-summary/#t=61.72 |
| inside Car’s | https://realpython.com/lessons/python-class-object-summary/#t=66.28 |
| .__init__() method, using self.speed = 3 assigns the value | https://realpython.com/lessons/python-class-object-summary/#t=67.28 |
| 3 to the attribute named .speed on the instance object. | https://realpython.com/lessons/python-class-object-summary/#t=72.19 |
| 01:18 | https://realpython.com/lessons/python-class-object-summary/#t=78.05 |
| An instance object has its own copy of the attributes. | https://realpython.com/lessons/python-class-object-summary/#t=78.05 |
| When you’re using the object from the outside, | https://realpython.com/lessons/python-class-object-summary/#t=81.78 |
| you use dot notation on the object to get at its attributes. Within | https://realpython.com/lessons/python-class-object-summary/#t=83.81 |
| an object’s method, | https://realpython.com/lessons/python-class-object-summary/#t=88.71 |
| you do the same thing with the object reference called self passed into each | https://realpython.com/lessons/python-class-object-summary/#t=89.71 |
| method. Attributes can also be at the class level. | https://realpython.com/lessons/python-class-object-summary/#t=93.83 |
| 01:38 | https://realpython.com/lessons/python-class-object-summary/#t=98.94 |
| These kinds of attributes are readable by all objects of that class. | https://realpython.com/lessons/python-class-object-summary/#t=98.94 |
| When you change a class attribute, | https://realpython.com/lessons/python-class-object-summary/#t=103.2 |
| all objects see the new value. Methods are a special kind of | https://realpython.com/lessons/python-class-object-summary/#t=105.15 |
| function associated with a class and its objects. | https://realpython.com/lessons/python-class-object-summary/#t=110.06 |
| 01:53 | https://realpython.com/lessons/python-class-object-summary/#t=113.9 |
| Instance methods are at the object level and require at least one argument named | https://realpython.com/lessons/python-class-object-summary/#t=113.9 |
| self, which is the reference of the calling object. | https://realpython.com/lessons/python-class-object-summary/#t=118.25 |
| Class methods are at the class level. | https://realpython.com/lessons/python-class-object-summary/#t=122.53 |
| 02:04 | https://realpython.com/lessons/python-class-object-summary/#t=124.95 |
| They have no knowledge of a specific object. | https://realpython.com/lessons/python-class-object-summary/#t=124.95 |
| You declare a method as a class method by wrapping it in the @classmethod | https://realpython.com/lessons/python-class-object-summary/#t=127.9 |
| decorator, and similar to the instance method, | https://realpython.com/lessons/python-class-object-summary/#t=131.28 |
| they also take at least one argument. In this case, | https://realpython.com/lessons/python-class-object-summary/#t=134.27 |
| it’s a reference to the class. Class methods are frequently used for factories, | https://realpython.com/lessons/python-class-object-summary/#t=137.43 |
| an alternative way of creating object instances. | https://realpython.com/lessons/python-class-object-summary/#t=142.58 |
| 02:26 | https://realpython.com/lessons/python-class-object-summary/#t=146.64 |
| The third type of method is a static method. | https://realpython.com/lessons/python-class-object-summary/#t=146.64 |
| These aren’t used very frequently in Python, | https://realpython.com/lessons/python-class-object-summary/#t=149.11 |
| and they require neither a class nor an object reference. | https://realpython.com/lessons/python-class-object-summary/#t=151.56 |
| To declare a static method, you wrap it in the @staticmethod decorator. | https://realpython.com/lessons/python-class-object-summary/#t=155.56 |
| 02:41 | https://realpython.com/lessons/python-class-object-summary/#t=161.72 |
| The descriptor protocol defines an interface that Python uses to create | https://realpython.com/lessons/python-class-object-summary/#t=161.72 |
| attribute-like behavior using methods. | https://realpython.com/lessons/python-class-object-summary/#t=166.1 |
| This gives you fine-grain control over how that thing that looks like an | https://realpython.com/lessons/python-class-object-summary/#t=169.05 |
| attribute actually behaves under the covers. | https://realpython.com/lessons/python-class-object-summary/#t=173.14 |
| 02:56 | https://realpython.com/lessons/python-class-object-summary/#t=176.56 |
| You turn a method into a property by wrapping it with the @property decorator. | https://realpython.com/lessons/python-class-object-summary/#t=176.56 |
| From the outside, it can be read like an attribute—i.e., without parentheses. | https://realpython.com/lessons/python-class-object-summary/#t=181.55 |
| 03:06 | https://realpython.com/lessons/python-class-object-summary/#t=186.34 |
| The user doesn’t need to be aware that this triggers an underlying method | https://realpython.com/lessons/python-class-object-summary/#t=186.34 |
| 03:11 | https://realpython.com/lessons/python-class-object-summary/#t=191.25 |
| Associated with the property is the @.setter decorator. | https://realpython.com/lessons/python-class-object-summary/#t=191.25 |
| This allows you to create a method that is called when you attempt to set the | https://realpython.com/lessons/python-class-object-summary/#t=195.03 |
| value of a property. Together, | https://realpython.com/lessons/python-class-object-summary/#t=198.8 |
| the property and setters are like getter and setters in other programming | https://realpython.com/lessons/python-class-object-summary/#t=200.99 |
| languages, | https://realpython.com/lessons/python-class-object-summary/#t=204.89 |
| except they hide away the corresponding methods, allowing the user to simply use | https://realpython.com/lessons/python-class-object-summary/#t=205.67 |
| the property like an attribute. | https://realpython.com/lessons/python-class-object-summary/#t=209.77 |
| 03:32 | https://realpython.com/lessons/python-class-object-summary/#t=212.19 |
| The descriptor protocol actually goes even deeper than this, | https://realpython.com/lessons/python-class-object-summary/#t=212.19 |
| but that will be covered in part two of the course. Speaking of part two, | https://realpython.com/lessons/python-class-object-summary/#t=215.19 |
| here’s a quick version of what you can look forward to. So far, | https://realpython.com/lessons/python-class-object-summary/#t=220.35 |
| you’ve been using the attributes and methods on a class, | https://realpython.com/lessons/python-class-object-summary/#t=224.15 |
| but classes have other features as well. | https://realpython.com/lessons/python-class-object-summary/#t=227.03 |
| 03:49 | https://realpython.com/lessons/python-class-object-summary/#t=229.75 |
| You can declare a class using another class in its definition. | https://realpython.com/lessons/python-class-object-summary/#t=229.75 |
| This is called inheritance and is a way of reusing the functionality of another | https://realpython.com/lessons/python-class-object-summary/#t=233.28 |
| class while augmenting it and not having to rewrite the code. | https://realpython.com/lessons/python-class-object-summary/#t=237.45 |
| 04:01 | https://realpython.com/lessons/python-class-object-summary/#t=241.94 |
| Inheritance can be multilevel: | https://realpython.com/lessons/python-class-object-summary/#t=241.94 |
| a class can inherit from a class, which inherits from a class, and so on. | https://realpython.com/lessons/python-class-object-summary/#t=244.15 |
| It can also inherit from multiple classes at the same level. | https://realpython.com/lessons/python-class-object-summary/#t=249.16 |
| 04:14 | https://realpython.com/lessons/python-class-object-summary/#t=254.1 |
| All together, these mechanisms provide a good way of writing reusable code. | https://realpython.com/lessons/python-class-object-summary/#t=254.1 |
| It also allows you to define hierarchical data structures that better map your | https://realpython.com/lessons/python-class-object-summary/#t=258.88 |
| data to how things appear in the real world. | https://realpython.com/lessons/python-class-object-summary/#t=263.3 |
| 04:28 | https://realpython.com/lessons/python-class-object-summary/#t=268.22 |
| That’s it for part one. I hope you found it informative. See you in part two. | https://realpython.com/lessons/python-class-object-summary/#t=268.22 |
| Sept. 8, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-bfecf610-8081-4fec-9202-bbfc53af7ff1 |
| Sept. 8, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-ef32438f-94f4-4469-ac25-c99cddd1f568 |
| Sept. 9, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-404795e9-c9b6-4f4e-bb31-02d0482ed846 |
| Sept. 10, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-e33e4be7-54b6-4bd9-ae31-cc0d2de5a957 |
| Oct. 2, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-08fd8e30-e506-4221-b441-c8de970813e7 |
| Dec. 9, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-84f9c2b8-5054-4a32-9747-00ed0efc7a7e |
| Dec. 9, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-81c8ff32-20df-4ab3-83f7-7431e1d92eab |
| Dec. 11, 2023 | https://realpython.com/lessons/python-class-object-summary/#comment-8a5ecfe0-4051-41e8-a406-a353ad023ec4 |
| Jan. 8, 2025 | https://realpython.com/lessons/python-class-object-summary/#comment-be8bf351-2013-44b6-928b-5b96e5cdca29 |
| Jan. 8, 2025 | https://realpython.com/lessons/python-class-object-summary/#comment-2df291c1-c47c-4db6-a97f-ffa506d31d44 |
| March 28, 2025 | https://realpython.com/lessons/python-class-object-summary/#comment-b143280e-289f-45ba-bf25-59e4d02a4b91 |
| March 29, 2025 | https://realpython.com/lessons/python-class-object-summary/#comment-4baaf8ea-0de1-47f1-9e07-b2472301df36 |
| Become a Member | https://realpython.com/account/join/ |
| https://realpython.com/lessons/python-class-object-review/ |
| Overview | https://realpython.com/courses/python-class-object/ |
|
Class Concepts: Object-Oriented Programming in Python (Overview) 03:22
| https://realpython.com/videos/python-class-object-overview/ |
|
The Case for Object-Oriented Programming 09:55
| https://realpython.com/videos/why-oop-python/ |
|
Class Creation 09:43
| https://realpython.com/lessons/python-class-creation/ |
|
Attributes 06:44
| https://realpython.com/lessons/python-attributes/ |
|
Properties and Descriptors 07:51
| https://realpython.com/lessons/python-properties-and-descriptors/ |
|
Class Methods 08:19
| https://realpython.com/lessons/python-methods/ |
|
A Complete Example: Putting It All Together 10:22
| https://realpython.com/lessons/python-class-object-review/ |
|
Class Concepts: Object-Oriented Programming in Python (Summary) 04:34
| https://realpython.com/lessons/python-class-object-summary/ |
| Privacy Policy | https://realpython.com/privacy-policy/ |
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover