A Deep Dive into Python's Dataclasses (Part 1)

preview_player
Показать описание
This two-part series of videos takes a deep dive into Python dataclasses.

The goal of these videos is not to learn just the mechanics of defining classes using dataclasses, but rather to understand how dataclasses add functionality to classes, and understand the equivalent code we would have to write using regular classes. Understanding dataclasses at this fundamental level will help you understand why certain things may or may not work in your own dataclasses and how to solve your issues.

So, don't expect a 10-minute run down of how to create dataclasses!!

#mathbyteacademy #dataclass #dataclasses #python

Content
=======
00:00:00 - Introduction
00:03:48 - Basics
00:13:29 - Equality Comparisons
00:17:35 - Hashability
00:21:02 - Immutability
00:30:36 - Ordering
00:39:08 - Serialization (dicts and tuples)
00:41:09 - Fields Introspection
00:43:06 - Recap of dataclass vs standard class so far
00:44:42 - Adding Custom Methods and Properties
00:45:58 - Application: Overriding Default Ordering
00:57:46 - Performance/Resource Considerations vs Named Tuples
01:05:32 - Conclusion & Up Next

Code for this Video
================

My Python Courses
=================

- Python 3 Fundamentals (introduction to Python)

- Pydantic V2: Essentials

- Python 3 Deep Dive (Part 1 - Functional)

- Python 3 Deep Dive (Part 2 - Iteration, Generators)

- Python 3 Deep Dive (Part 3 - Hash Maps)

- Python 3 Deep Dive (Part 4 - OOP)

Fundamentals and Deep Dive Jupyter Notebooks
========================================
All fully-annotated Jupyter notebooks from my Udemy courses are freely available on GitHub:

Рекомендации по теме
Комментарии
Автор

Hey Fred - You never fail to amaze your students. You are such a gifted teacher who can simplify anything and everything. Big kudos to you.

TheAshutoshBhardwaj
Автор

You are the best Fred, thank you very much for sharing your knowledge

FirasShamasnehM
Автор

Even before starting the video I know that it's going to be awesome. Kudos Fred ! Would love a series on implementing various design patterns using python.

butterhalves
Автор

I just finished the udemy deepdive-1 and now half-way deepdive-2. But could not resist to watch this stand-alone course video right now. This is also a great video with the same level of detail as the deepdive series. Great added value !!! 😀

drgregoryhouse
Автор

Am excited to watch this when I get the chance.🎉

warrenmarkham
Автор

Thanks for all the work you do. Your python lectures are best I've seen. Just as a suggestion... you should include a 30 second advert for your udemy courses at the start of each of your YouTube videos. This would help those looking to learn Python as well as grow your Udemy following

fatfrankie
Автор

Amazing video! That is a lot of great information. I thought I knew enough of dataclasses but learned a lot in this video. Thanks!

kosmonautofficial
Автор

Oh! I can't resist to write a comment here! It was a very deep dive in dataclasses! Perfect material! Thank you very much!!!

Ilya_Akchurin
Автор

I happy to hear your familiar voice, I didn't know what's your YouTube channel before

tannguyen_
Автор

Great lecture on dataclasees Fred, I especially enjoyed the comparison section with name tuples. Can't wait for the follow up video.

modikai
Автор

You are amazing Fred. Everytime I open youtube app, I check if you released new video. Awesome explanation. Can you please make videos on Machine learning concepts and maths required for machine learning?

ashishsaraswat
Автор

Hi Fred, Great video, !! thanks for sharing the "in deep" of things.! I was wondering if sometime in the future you could do some comparison between attrs and dataclasses and when to use one or the other. Big kudos!!

valentinplechuc
Автор

To be honest I didnt know about dataclasses so I was just using normal classes with __slots__, but 95% of what dataclasses do I was already doing with inheritance, only had to write the __repr__ and all that once, plus most of the dunder methods are useless. But yeah I will switch to dataclasses to avoid writing the __init__, but thats about it

zizvjog
Автор

Hi Fred, thank You for another great content and such explanation. Have a small question.
24:20 You added private attributes x, y and radius. Should we also make them private in all other methods __repr__, __eq__ and __hash__? Because it looks like You did not make them private in those methods and in the video they only private in properties You add.

dukex
Автор

Hey Fred, great breadth and depth as always.
A question regarding dataclasses sorting 47:15, would using a __post_init__ method be an alternative to sort using radius and/or euclidean distance, for example
```
@dataclass(order=True)
class CircleD:
sort_index: int = field(init=False, repr=False)
euclidean_dist: float = field(init=False, repr=False)
x: int = 0
y: int = 0
radius: int = 1

def __post_init__(self):
self.sort_index = self.radius
self.euclidean_dist = dist((0, 0), (self.x, self.y))
```

packetporter
Автор

I love your videos, amazing content in Udemy and Youtube. Any plans of making a playlist on Data Structures and algorithms😀

sandeepsingavarapu
Автор

Thanks! Did you start using dataclass more often? In which cases?

pavelekshin
Автор

Hi Fred, will you ever make a course on Udemy about making interesting projects using all different techniques of Python? I would love it!!

MindfreeLetsgo
Автор

Hi Fred, thanks for creating these wonderful lessons. I am trying to understand how python is letting us allow a dictionary with duplicate keys (minute 23.35) in the video, what 's the explanation here, i was expecting the second circle to overwrite the first entry

igbjqej
Автор

Im not an expert but I think your size comparisons are wrong. When u do the os.size or whatever, it only gives you part of the info on size, I seem to remember only like the reference to the class or something, i.e. a class with one attr will be the same size apparently as one with 100

zizvjog
visit shbcf.ru