Think Python: How to Think Like a Computer Scientist

(singke) #1

I’ve got a function that doesn’t return what I expect.


If you have a return statement with a complex expression, you don’t have a chance to
print the result before returning. Again, you can use a temporary variable. For example,
instead of:


return  self.hands[i].removeMatches()

you could write:


count   =   self.hands[i].removeMatches()
return count

Now you have the opportunity to display the value of count before returning.

Free download pdf