Check If a Function Returns False in Python

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?

3

1 Answer

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)

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest