-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doing nothing with pass and Ellipsis
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Doing nothing with `pass` and `Ellipsis` | ||
|
||
In python, you can do nothing by typing `pass` - people also use `...` (`Ellipsis`), but this is also used in other places. | ||
|
||
For ignoring exceptions: | ||
|
||
```python | ||
try: | ||
f(x) | ||
except ValueError: | ||
pass | ||
``` | ||
|
||
For writing skeleton code (to me, `pass` looks like it's intended to be empty, `...` looks like it will be filled in later). | ||
|
||
```python | ||
def my_fcn(): | ||
... | ||
``` | ||
|
||
You can put anything in place of the `...` here though, so people often just write a docstring: | ||
|
||
```python | ||
def my_fcn(): | ||
""" | ||
Do some things and stuff | ||
""" | ||
``` | ||
|
||
Via: [Richard](https://github.com/richard-lane) | ||
|
||
## Postscript | ||
|
||
For skeleton code you could also do: | ||
|
||
```python | ||
def my_fcn(): | ||
raise NotImplementedError | ||
``` | ||
|
||
or: | ||
|
||
```python | ||
def my_fcn(): | ||
return NotImplemented | ||
``` | ||
|
||
(these do different things) |