I keep getting a KeyError when I use a variable as [key] in [dictionary].pop([key])
<p>I don't get KeyError when I use a constant (whose value is the same as the variable) for [key].</p>

<p>For example: </p>

<pre><code>self._answer= input("Which appointment would you like to delete?")
self._useless= self._book.pop(self._answer)
</code></pre>

<p>Gives a key error when self._answer= 1001, however:</p>

<p><code>self._useless= self._book.pop(1001)</code></p>

<p>works as desired. Any ideas how I can resolve this issue?</p>

<p>Edit: As @user2357112 suggested below, the following piece of code worked: <code>def deleteAppointment(self):
        self._answer= int(input("Which appointment would you like to delete?"))
        del self._book[self._answer]</code></p>

<p><strong>However</strong>, after redoing  the entire project I no longer ran into the problem above (i.e. using [dictionary].pop([key]) no longer produced a KeyError). <strong>Therefore, if you are getting this error there is likely a bug in your code.</strong></p>