4 ms·
> And honestly, I would be rich if I got a dollar every time a student does this: > msg.upper() > Instead of: > msg = msg.upper() > And then call me
by pbowyer 6y ago
> And honestly, I would be rich if I got a dollar every time a student does this:
> 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?
- BiteCode_dev 6y agoA 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.
- pansa2 6y ago> 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-string-functions https://docs.python.org/2/library/string.html#deprecated-str...