Jason Donegan
Jason Donegan

Reputation: 49

Boolean not callable

I am new to python, and still trying to learn. I am getting the bool not callable error, can someone help me. I am completely confused on how to solve this issue.

def is_equal(num1,num2):
    return bool (num1 == num2)

e = is_equal(2,2)

if e == True():
    print("Is equal")

else:
    print("Not equal")

Upvotes: 0

Views: 258

Answers (2)

Venti Fang
Venti Fang

Reputation: 11

def is_equal(num1,num2): return bool (num1 == num2)

e = is_equal(2,2)

if e == True(): print("Is equal")

else: print("Not equal")

After 'True', you can't add '()'.'True' is a Boolean variate.

Upvotes: -1

wasif
wasif

Reputation: 15488

True is actually boolean value not a callable function:

def is_equal(num1,num2):
    return bool (num1 == num2)

e = is_equal(2,2)

if e == True:
    print("Is equal")
else:
    print("Not equal")

Even shorthand is if e:

def is_equal(num1,num2):
    return bool (num1 == num2)

e = is_equal(2,2)

if e:
    print("Is equal")
else:
    print("Not equal")

As @ShadowRanger mentioned you don't need to explicitly convert the result to bool:

def is_equal(num1,num2):
    return num1 == num2

Upvotes: 2

Related Questions