__new__ vs __init__ in Python

Try Hostinger: Use coupon code MCODING at checkout for up to 91% off all yearly hosting plans! Thanks to Hostinger for sponsoring this video! IN THIS VIDEO... --------------------------------------------------- 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 () Source code: Python new docs: # tp_new in CPython: C extension example: #existing-pointers-instantiation Singleton pattern: SUPPORT ME ⭐ ---------------------------
Back to Top