Skip to content Skip to sidebar Skip to footer

Passing Boolean Function To If-condition In Python

I'm learning python, and I'm trying to do this, which I thought should be trivial, but apparently, it's not. $python >>> def isTrue(data): ... 'ping' in data ... >

Solution 1:

You actually need to return the value. Then, it will work.

>>> def isTrue(data):
...     return "ping" in data
... 
>>> if isTrue("ping"):
...     print("pong")
...
pong
>>>

Post a Comment for "Passing Boolean Function To If-condition In Python"