Complete the code to set a session variable named 'user_id' to 42.
request.session[[1]] = 42
Session keys must be strings, so the key 'user_id' is set as a string in brackets.
Complete the code to get the session variable 'user_id' safely with a default of None.
user_id = request.session.[1]('user_id', None)
The get method retrieves a session value safely, returning None if the key does not exist.
Fix the error in the code to delete the session variable 'user_id'.
del request.session[1]To delete a session key, use del request.session['key'] with square brackets and quotes.
Fill both blanks to check if 'user_id' exists in session and then get it.
if [1] in request.session: user_id = request.session.[2]('user_id')
Check if the string key 'user_id' is in session, then use get to retrieve it.
Fill all three blanks to set a session variable 'cart' to an empty list if not present, then append 'item1'.
if [1] not in request.session: request.session[[2]] = [] request.session[[3]].append('item1')
Use the same session key 'cart' as a string in all places to check, set, and append.