Alex Rivera | Logout

Check if a function returns false in Python

Asked 2012-08-23T18:30:25.347
28

In python, I am currently doing this:

if user_can_read(request.user, b) == False:

Is there any other way of checking if the function returns False?

Edit
Report

1 Answer

48

You could just use

if user_can_read(request.user, b):
    ## do stuff

If user_can_read returns anything (except 0, False, etc), it will be considered True, and do stuff.

And the negation: if not user_can_read(request.user, b)

answered 2012-08-23T18:33:13.240

Your Answer