Strings are immutable. You can change a variable that references a string, so that it references a new string, but never actually modify a str
object.
x = "Hello" # x references the "Hello" string
x = x + " World!" # x references a NEW "Hello World!" string
The actual string object holding "Hello"
never changes. It only gets swapped for another string object.
So, instead of modifying the strings in your list (impossible), you need to change the items in the list for new strings.
for index, url in enumerate(some_list):
some_list[index] = constant_prefix + url
The old string objects you're no longer using are discarded, and replaced in the list by the new strings.
Your previous version only modified the url
variable, with no effect outside the iteration loop.
Mark Ransom, in his answer, suggested the more pythonic way: creating a new list using a comprehension:
new_urls = [constant_prefix + url for url in original_urls]
Give him an upvote =)