__new__ vs __init__ in Python

mCoding
mCoding
206.5 هزار بار بازدید - 3 سال پیش - What's _new_ and what's the
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: 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: discord
Github: https://github.com/mCodingLLC/
Reddit: Reddit: mCoding
Facebook: 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
3 سال پیش در تاریخ 1400/07/03 منتشر شده است.
206,539 بـار بازدید شده
... بیشتر