題目: 讓以下function回傳 True
原文: https://www.reddit.com/r/Python/comments/cje5yh/short_python_challenge_make_this_return_true/
| |
解答一: -7
在 Python 中,整数 -5 到 256 會預先分配到記憶體,
此時 -7 + 1 得到的 -6,恰好在這範圍之外,
才會出現 -6 is not -6 的情況
解答二: 自定義class
透過實現 add,讓他可以與integer互動, 但其實就是拿來判斷 integer 後,回傳適當的 boolean (有點作弊XDD)
| |
