我正在学习python,我试图这样做,我认为这应该是微不足道的,但显然,它并非如此。
$python
>>> def isTrue(data):
... "ping" in data
...
>>> if isTrue("ping"):
... print("pong") >>>>>>>>>>>>>> shouldn't this print "pong"???
...
>>>
答案 0 :(得分:1)
您实际上需要返回该值。 然后,它会起作用。
>>> def isTrue(data):
... return "ping" in data
...
>>> if isTrue("ping"):
... print("pong")
...
pong
>>>