Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Understanding Attributes - They're Not Nearly as Boring as You Think

PyCon US via YouTube

Overview

Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
Explore the intricacies of Python attributes in this PyCon US talk by Reuven M. Lerner. Delve into the seemingly mundane yet crucial aspect of Python programming, uncovering the hidden complexities behind the simple dot notation. Learn about attribute lookup, inheritance, and the distinction between methods and functions. Discover the power of properties in creating attributes that behave like setters and getters. Examine the descriptor protocol and its role in enabling key Python functionalities, including the automatic insertion of "self" as the first argument in method calls. Through practical examples and clear explanations, gain a deeper understanding of how attributes shape Python's behavior and how to leverage them effectively in your code.

Syllabus

Intro
I teach Python!
Let's assign to a variable!
Let's get fancier
Variables vs. attributes
Reading from attributes
Setting attributes
We set attributes all the time
What's missing from this program?
Idea: A global variable
A better alternative
This is pretty ugly
What will this code print?
The answer
Methods are class attributes
Classes are file-less modules
Class attribute, nicer edition
Static variables.!?
Let's walk through this
A new version of Person
We need a new class
Does it work?
Try again, but with inheritance
Let's use inheritance
Better use of inheritance
The problem?
Solution: Explicitly call Person.init
Better: Use super
Printing our objects
Operator overloading
Something is still missing
Example
Use it in a class attribute
Retrieve the value
What are gets parameters?
Methods are descriptors
Where is our original function?

Taught by

PyCon US

Reviews

Start your review of Understanding Attributes - They're Not Nearly as Boring as You Think

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.