What does it mean to say if n? I don't get why if n works in an if statement. Shouldn't there be an argument such as if n == 0 or something, not just if n?
def AddMusicAtPosition(self, newMusic, n):
if n:
self.nextMusic.AddMusicAtPosition(newMusic, n - 1)
else:
newMusic.nextMusic = self.nextMusic
self.nextMusic = newMusic
In Python, if n is equivalent to if bool(n).
For integers, bool(i) equals to i != 0.
If n is an instance of a class, then
__bool__, then n.__bool__() is called__bool__ but __len__, then n.__len__() != 0 is evaluated__bool__ nor __len__, it always evaluates to True (think like n is not None).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With