Under and Dunder - Python secret functions
Cheuk Ting Ho (~Cheukting) |
You may know dunder init (
__init__), but how well do you know about other Python “magic” functions? Why are dunder functions not accessible? Where are they hiding? What purpose do they serve? in this talk, I am going to show you the secrets of the Dunder functions and what purposes do they have. Once the mystery is solved, we will see the true beauty of those functions.
At the start of this adventure, we will be using
dir to look into the secret functions Python objects have. Eg:
__next__ Then, we will investigate where does the dunder function goes and the reason why is it not accessible externally. We will also find out how did Python treat them internally.
Once we get warmed up, we will have a deeper look. We will see by overloading these dunder methods, we can change the behaviour of the operator on Python objects. We will learn how operator overload is performed in Python. We will also showcase a few examples when this is useful when we want to write "beautiful" codes.
And in the end, we will see what other magics dunder methods could do. We will see how dunder functions can change the identity of the Python objects. Through some experiments and looking at the bytecodes, we will have a brief idea of how Python works internally.
This talk is for attendees who have just begin their Python journey. By explaining the dunder functions and the nature of Python objects, attendees will have a better understanding of why Python is fundamentally different from other programming languages. Hopefully, this knowledge will help them out when they continue their Python journeys.
This talk is for beginners so everyone is welcomed. However, knowing some Python basics is recommended.
After spending 5 years researching theoretical physics at Hong Kong University of Science and Technology, Cheuk has transferred her analytical and logical skills in natural science and built a career in data science. Cheuk has been a Data Scientist in one of the biggest worldwide wholesalers in the travel business; an AWS partnered consultancy which delivers machine learning model; a startup aiming to revolutionise revenue management with data science and; a global bank using machine learning to investigating financial crime. Now Cheuk is working in a team of developers building a revolutionary graph database - TerminusDB.
Cheuk constantly contributes to the community by giving AI and deep learning workshops and organize sprints for open source projects, at the same time contribute to open source projects including Pandas, Keras, Scikit-learn, Dateutil and maintaining her open-source library - PicknMix. Cheuk has also been a guest speaker at Universities and various conferences. Believing in gender equality, Cheuk is currently a co-organizer of AI Club for Gender Minorities to support Tech Diversity and Inclusion. On top of speaking at conferences, Cheuk has joined the organizing team of EuroPython and PyData Global.
Find everything about me on my website: cheuk.dev