What is the difference between request.GET['q'] ,request.GET('q'),and request.GET('q',)
<p>What is the difference between request.GET['q'] ,request.GET('q'),and request.GET('q',).Thanks</p>

<pre><code>def search(request):
    if 'q' in request.GET and request.GET['q']:
        q=request.GET['q']
        books=Book.objects.filter(title__icontains=q)
        return render(request,'search_results.html',{'book':books,'query':q})
    else:
        return HttpResponse('please submit a search term')
</code></pre>

<p><code>if 'q' in request.GET and request.GET['q']</code> it just check for dictionary contains that <code>q</code> key. But it looks ugly. You can do it more pythonic:  </p>

<pre><code>q = request.GET.get('q') # returns None if q not in GET
if q:
    do your logic
</code></pre>

python django