Skip to content

Python check if the function returns True | Example code

  • by

Using the if statement you can find the function returned true or not in Python. This step is needed some time in order to proceed to the next step of a separate function.

if function_Name(argu):
    # do_something

Python check if the function returns True Example

Simple example code.

def validate_age(age):
    if age > 20:
        return True
    else:
        return False


# Print value
print(validate_age(23))

# Check true
if validate_age(23):
    print("validate_age function returns True")
else:
    print("validate_age function returns False")

Output:

Python check if the function returns True

Do comment if you have any doubts and suggestions on this Python function code.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *