Python Properties vs Methods: The Contract You Didn’t Know You Were Making
66K views · Feb 20, 2026 · Education
Comments · 108
@ArjanCodes · 6 months ago (edited) · pinned
🧱 Build software that lasts. Join the Software Design Mastery waiting list → <a href="https://arjan.codes/mastery">https://arjan.codes/mastery</a>.
@cfossto · 7 months ago
Imma spam this video to an entire team I worked with... "just because you can, doesn't mean you should".
76
@realms4219 · 7 months ago (edited)
All our Python scripting is written by Java programmers. How can I tell? How can I NOT tell lmfaooo this video is finally giving me confirmation
18
@wtzeb · 7 months ago (edited)
Incredibly happy you're still digging into the code and creating these videos.
19
@UNgineering · 7 months ago
between awaiting a property and saving-on-assignment, i think i have a way to completely poison OpenAI training dataset on python
23
@caujka · 6 months ago
Thanks for the explanation! You brought awesome examples to illustrate the idea!
@Exolodem · 7 months ago
Great Video!
1
@sleeping_monkey · 7 months ago (edited)
<a href="https://www.youtube.com/watch?v=wHLZ_uTrCYA&t=500">8:20</a> There's another way to define properties<br><br>def get_is_active(self) ...<br>def set_is_active(self, value) ...<br><br>is_active = property(get_is_active, set_is_active)<br><br>And you can actually define a write-only property this way:<br><br>def set_is_active(self, value) ...<br>is_active = property(None, set_is_active)<br><br>or<br><br>is_active = property(fset=set_is_active)<br><br>You can take it further and create a delete-only property...
19
@malteplath · 7 months ago
I totally agree with your suggestion about the use of properties. One specific other use case would be to fake an interface: If some third party function expects an attribute but it is not an attribute (but rather a derived "property") of your class, a @property is the perfect fit. - rather than writing a complete wrapper around your existing class.<br>I am looking forward to your video on descriptors. I have not managed to get my head around those! Pure (black) magic to a mere human.
2
@tonny_dourado · 7 months ago
Async properties is a crazy concept, my first instinct was it wouldn't work, but when I thought about it a bit, it clearly works. Feels like an almost unintended interaction between features, though 😅
13
@srh1034 · 6 months ago
Something I really love about your tutorials is the depth of knowledge your share, but what I do not like and I belive is the biggest shortcoming of yur videos is taht so many words are used to explain, rather than just some simple graphics when explaining and then actual implementation which you do amazingly! Big fan anyway!
@edvardasposka · 7 months ago
Properties can be write-only, i.e. by tweaking the getter method of properties we can create create write-only attributes. We can make our getter method raise an exception every time a user accesses the underlying attribute, e.g. <br>@property<br> def password(self):<br> raise AttributeError("Password is write-only")<br><br>@password.setter<br> def password(self, plaintext):<br> salt = os.urandom(32)<br> self._hashed_password = hashlib.pbkdf2_hmac(<br> "sha256", plaintext.encode("utf-8"), salt, 100_000<br> )<br>This turns "password" into a write-only attribute. Then we store the resulting hashed password in the non-public attribute, doing so ensures that we never save the "plaintext" password in any retrievable attribute.
2
Up next

How to Write Python That Feels Like Python
ArjanCodes · 174K views

10 Python Features You’re Not Using (But Really Should)
ArjanCodes · 76K views

How To Keep Building Side Projects in AI era?
Vitalii Honchar · 183 views

A Helping Hand for LLMs (Retrieval Augmented Generation) - Computerphile
Computerphile · 171K views

Protocols vs ABCs in Python - When to Use Which One?
ArjanCodes · 90K views

HTTP Clients and Client Factory in C#
Full-Stack Felton · 85 views

The Builder Pattern in Python: Finally Explained!
ArjanCodes · 65K views

Claude Took On the Riemann Hypothesis. Here’s What Actually Happened
Ellie Sleightholm · 479K views

Why Dataclasses Disappear in Real Python Applications
ArjanCodes · 137K views

You Think This Is Good OOP… It’s Not
ArjanCodes · 74K views

How to Write Great Unit Tests in Python
ArjanCodes · 49K views

Python Decorators - Visually Explained
Visually Explained · 369K views

Don’t Use Boolean Flags in Python, Use Policies Instead
ArjanCodes · 165K views

The State Pattern in Python (Real Examples)
ArjanCodes · 94K views

Better Python Code: Ditch the Dictionaries
ArjanCodes · 29K views

7 Things You Didn’t Know Dataclasses Could Do
ArjanCodes · 48K views

What is Typst? The Modern LaTeX Alternative
Dr Lyndon Walker · 81K views

Dependencies, Wheels, and Lock Files Explained - Python Packages
Caleb Curry · 3K views

Python OOP Tutorial 6: Property Decorators - Getters, Setters, and Deleters
Corey Schafer · 1M views

Stop Overwriting State And Use Event Sourcing Instead
ArjanCodes · 35K views