Python function returns Only True or False value | Code

  • by

Use a Boolean variable inside function which always return returns a value True or False in Python. Set initial value of variable true and false then change it according to the conditions.

Example function returns Only True or False value in Python

Simple example code gets the true or false return value.

def foo(a, b):
    answer = False

    if a > b:
        answer = True
    return answer


print(foo(12,3))

Output:

Python function returns Only True or False value

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

Note: IDE: PyCharm 2021.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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.