How to check if there is a tuple with a list or dictionary

I have a tuple:

details = ({}, [])

Since there is no data in the next court, I want to return a null answer. For this, I write:

 if not details:
      return Response({})
 else:
    print "Not null"

But this does not seem to work, as it always goes in parts else, and printing is not null. I am new to python. Any help is appreciated.

+4
source share
1 answer

Note : if you write:

if <expr>:
    pass

Python , <expr> == True, <expr>, "". True False True False. None False, True , , (, , , ..), True, . True , __bool__ ( __len__), .

True, ( False ). , .

, True, any(..):

if not any(details):  # all items are empty
    return Response({})
else:
    print "Not null"

, , , , , , else , if .

, True, all(..):

if not all(details):  # one or more items are empty
    return Response({})
else:
    print "Not null"
+10

Source: https://habr.com/ru/post/1693310/


All Articles