> For the complete documentation index, see [llms.txt](https://lei-d.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lei-d.gitbook.io/leetcode/python-tips/dictionaryget-vs-dictionary.md).

# dictionary.get( ) vs dictionary\[ ]

`dictionary.get` allows you to provide a default value if the key is missing:

```python
dictionary.get("bogus", default_value)
```

returns`default_value`(whatever you choose it to be), whereas

```python
dictionary["bogus"]
```

would raise a`KeyError`.

If omitted,`default_value`is`None`, such that

```python
dictionary.get("bogus")  # <-- No default specified -- defaults to None
```

returns`None`just like

```python
dictionary.get("bogus", None)
```

would.

Reference: <https://stackoverflow.com/questions/11041405/why-dict-getkey-instead-of-dictkey>
