> String.upper(msg)
That was the original syntax [0], before the string functions became methods. I agree that a method more strongly implies mutation than a function does.
Also, for consistency with list methods like `reverse` (which acts in place) and `reversed` (which makes a copy), shouldn’t the method be called `uppered`?!
[0] https://docs.python.org/2/library/string.html#deprecated-str...
'uppercased'
Ah, of course.
Also, it looks like that’s the name that Swift uses.
Re:The PEPs of Python 3.9
by BiteCode_dev on Thursday May 28, 2020 @06:26PM
(#23343624)
A student don't know anything about mutability, and since Python signatures are not explicit, there is no way to know they have to do that.
It's just something to be told. A design decision, like there are thousands to learn in IT, that you just can't guess.
> msg.upper()
> Instead of:
> msg = msg.upper()
> And then call me to say it doesn't work.
On this, isn't the student's reasoning sensible? E.g. "If msg is a String object that represents my string, then calling .upper() on it will change (mutate) the value, because I'm calling it on itself"?
If the syntax was upper(msg) or to a lesser extent String.upper(msg) then the new-to-programming me would have understood more clearly that msg was not going to change. Have you any insights into what your students are thinking?