mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-10-09 14:31:13 +00:00
Website snapshot
This commit is contained in:
parent
ee0ab66d73
commit
50ec3688a5
281 changed files with 21066 additions and 0 deletions
16
content/blog/notimplemented.md
Normal file
16
content/blog/notimplemented.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
title: "NotImplemented"
|
||||
date: 2019-10-27T23:35:17-04:00
|
||||
draft: false
|
||||
---
|
||||
|
||||
Let's say you overwrite the `__mul__` operator in a class in Python, but you don't want the function to be called for all kinds of input. You can specify the type by just returning `NotImplemented` for types you don't want.
|
||||
|
||||
```python
|
||||
class A:
|
||||
def __mul__(self, x):
|
||||
if not isinstance(x, A):
|
||||
return NotImplemented
|
||||
return someOperation()
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue