What does the second argument of the Session.pop method do in Python Flask?

flask, python, session

Solution

According to Flask's API their `Session` class is a wrapper around a python `Dict`. According to the python documentation for `dict.pop()`:

`pop(key[, default])`

If `key` is in the dictionary, remove it and return its value, else return `default`. If `default` is not given and `key` is not in the dictionary, a `KeyError` is raised.

In this case the tutorial asks you to pass in `None` as the `default` value.

Problem

I'm working through the Flask tutorial and would just like to clarify exactly what the .pop attr of the session object does and why it would take a 'None' parameter. ``` @app.route('/logout') def logout(): session.pop('logged_in', None) flash('You were logged out') return redirect(url_for('show_entries')) ```

Original source