Skip to content

Commit

Permalink
Doing nothing with pass and Ellipsis
Browse files Browse the repository at this point in the history
  • Loading branch information
jatonline authored Aug 12, 2024
1 parent eff3f65 commit bba613b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Python/pass-and-ellipsis.md
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)

0 comments on commit bba613b

Please sign in to comment.