How to write smart code using NotImplemented : Python

Pubblicato il: 17 novembre 2021
sul canale di: Anup Gogoi
83
1

Please join in this group https://chat.whatsapp.com/BCEHZqe6PbQ... for on demand doubt clearing sessions. Please connect with me for any queries. I will answer your questions.



A special value which should be returned by the binary special methods (e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g. __imul__(), __iand__(), etc.) for the same purpose. It should not be evaluated in a boolean context. NotImplemented is the sole instance of the types.NotImplementedType type.

Note When a binary (or in-place) method returns NotImplemented the interpreter will try the reflected operation on the other type (or some other fallback, depending on the operator). If all attempts return NotImplemented, the interpreter will raise an appropriate exception. Incorrectly returning NotImplemented will result in a misleading error message or the NotImplemented value being returned to Python code.
See Implementing the arithmetic operations for examples.
Note NotImplementedError and NotImplemented are not interchangeable, even though they have similar names and purposes. See NotImplementedError for details on when to use it.
Changed in version 3.9: Evaluating NotImplemented in a boolean context is deprecated. While it currently evaluates as true, it will emit a DeprecationWarning. It will raise a TypeError in a future version of Python.


In questa pagina del sito puoi guardare il video online How to write smart code using NotImplemented : Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Anup Gogoi 17 novembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 83 volte e gli è piaciuto 1 spettatori. Buona visione!