0

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
... 
>>> if isTrue("ping"):
...     print("pong")       >>>>>>>>>>>>>> shouldn't this print "pong"???
... 
>>>

1 Answer 1

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
>>>
Sign up to request clarification or add additional context in comments.

3 Comments

Oooh! That makes sense! Jeese, I can't believe being a java-pgrammaer for all these years, I could forget such a thing. I always thought Python was the "magic" language where you could almost write anything, and the interpreter would understand. :)
@OneTwoThree, python is awesome no doubt. But we all have limits. :)
If you do not have an explicit return, python will return the value None -- so it is kindof magic still. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.