0

This function:

def posts(request):

    # Get start and end points
    start = int(request.GET.get("start") or 0)
    end = int(request.GET.get("end") or (start + 9))

    # Generate list of posts
    data = []
    for i in range(start, end + 1):
        data.append(f"Post #{i}")

    # Artificially delay speed of response
    time.sleep(1)

    # Return list of posts
    return JsonResponse({
        "posts": data
    })

in view.py, what is or in these two lines?

start = int(request.GET.get("start") or 0)
end = int(request.GET.get("end") or (start + 9))
parmer_110
  • 325
  • 2
  • 11
  • Read the duplicates to understand how `or` is used as a conditional assignment operator, but in your case it is not necessary as you can pass a default value to `.get()` (i.e. `start = int(request.GET.get("start", 0))`). – Selcuk Mar 07 '23 at 04:03
  • 2
    The definition of `x or y` in Python is `x if x is true, otherwise y`. – Tim Roberts Mar 07 '23 at 05:23
  • @TimRoberts, Thank you for this answer simplicity. – parmer_110 Mar 07 '23 at 13:23

0 Answers0