I have the following statement:
if Game.item_can_move(item_target) == True:
return True + ""
else:
return False + ", error"
but this doesn't seem to work. I would like to return a bool, str in both of the return.
I have the following statement:
if Game.item_can_move(item_target) == True:
return True + ""
else:
return False + ", error"
but this doesn't seem to work. I would like to return a bool, str in both of the return.
You can use three strategies here,
class Foo:
def __init__(self):
self.foo = "foo"
self.is_bar = True
def my_method():
return Foo()
tmp = my_method()
print(tmp.foo)
print(tmp.is_bar)
def my_method():
foo = "foo"
is_bar = True
return foo, is_bar
def my_method():
foo = "foo"
is_bar = True
return [foo, is_bar]
You can return multiple things at once with commas:
if Game.item_can_move(item_target) == True:
return True, ""
else:
return False, "error"
The reason your code didn't work is because you cannot concat a python str
with a bool
type. You can, however, do:
if Game.item_can_move(item_target) == True:
return str(True) + ", "
else:
return str(False) + ", error"
BTW, your code can be simplified:
b = Game.item_can_move(item_target)
if b:
return b, ""
return b, "error"