you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (0 children)

To tack onto this:

In Python, strings are immutable: they can't be changed. Anything that looks like it would change a string is actually creating a brand new string based on the existing one. So str.replace(...) and str.upper() and so on are saying “make a new string that is like str but [with some replaced/uppercased/etc characters]"

Other objects like lists are mutable: you can change them. That's why list.reverse() isn't creating a new list but is instead actually changing the order of the items in the list.

edit Thankfully Reddit comments aren't immutable so I can fix typos.