Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
website = 'http://www.python.org' website[18:] = 'com'
The error says:
'str' object does not support item assignment.
Why is this code snippet not legal?
Because strings are immutable. Do it like this:
>>> website = 'http://www.python.org' >>> website = website[:18] + 'com' # build a new string, reassign variable website >>> website 'http://www.python.com'
Add a comment
If you prefer not to count how many characters to stop before you reach .org
.org
you can use
website=website[:len(website)-4]+".com"
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.