__new__ vs __init__ in Python
mCoding mCoding
224K subscribers
203,615 views
0

 Published On Sep 25, 2021

What's _new_ and what's the difference vs. __init__?
Try Hostinger: https://hostinger.com/mcoding
Use coupon code MCODING at checkout for up to 91% off all yearly hosting plans!

What's the difference between the "__new__" and "__init__" magic methods in Python? New is for object creation, and init is for object initialization. It is rare that a programmer would actually need to override new, so let's see some examples of how it can be used.

― mCoding with James Murphy (https://mcoding.io)

Source code: https://github.com/mCodingLLC/VideosS...
Python new docs: https://docs.python.org/3/reference/d...
tp_new in CPython: https://github.com/python/cpython/blo...
C extension example: https://cython.readthedocs.io/en/late...
Singleton pattern: https://en.wikipedia.org/wiki/Singlet...

SUPPORT ME ⭐
---------------------------------------------------
Patreon:   / mcoding  
Paypal: https://www.paypal.com/donate/?hosted...
Other donations: https://mcoding.io/donate

Top patrons and donors: Laura M, Jameson, John Martin, Dragos C, Vahnekie, Pieter G, Sigmanificient, Casey G

BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord:   / discord  
Github: https://github.com/mCodingLLC/
Reddit:   / mcoding  
Facebook:   / james.mcoding  

CHAPTERS
---------------------------------------------------
0:00 Intro
0:50 New vs init
2:51 Main purpose, subclassing immutable types
5:03 Singleton example
6:35 Client caching example
7:58 Encrypted file example
10:33 Metaclasses

show more

Share/Embed