Hopefully not a silly question. If I write
str1 = 'exterminate!'
str1.upper()
print(str1)
str1 = str1.upper()
print(str1)
my_list = [1, 2, 3]
my_list.append(4)
print(my_list)
my_list = my_list.append(5)
print(my_list)
The output is:
exterminate!
EXTERMINATE!
[1, 2, 3, 4]
None
In other words,
str1.upper()
and
my_list.append(4)
do very different things. By that, I mean .append actually changes the list object, but .upper() does not.
However, in order to change the string object to all uppercase, we have to use
str1 = str1.upper()
but doing
my_list = my_list.append(5)
we now have my_list as a noneType.
Can someone explain this behavior. I have a feeling it has to do with the fact that they are different object types.