I'm practicing for my exam and there are always questions asking whether a method changes an object in place or creates a new object. I wonder if there are any general rules applied to this or if I just have to memorise the outcome for different methods?
The examples from my exam are:
s = 'horse' s.upper() print(s)
this will generate
horse and not
HORSE, and thereby s is not changed by
l = [1, 3, 2] l.sort() print(l)
[1, 2, 3] and not
[1, 3, 2], and thereby l is changed by
Are there any ways to differentiate between these?