There's a phenomenon I've noticed in Python that I'd like to understand but I don't know what words to use to describe it or find documentation.
Compare the following sequences:
1)
a = ['my', 'nice', 'new', 'list']
a.reverse()
print(a)
>>> ['list', 'new', 'nice', 'my']
2)
b = 'my nice new string'
b.swapcase()
print(b)
>>> 'my nice new string'
Why is it that, for the second sequence, in order for print to give 'MY NICE NEW STRING', I would have to write
b = b.swapcase()
print(b)
? Or conversely, why DON'T I have to write a = a.reverse() before print(a) in the first sequence? What is the principled reason for why some of these methods need to be explicitly assigned to variables while others are implicitly stored in the variable that they're used upon?