Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A student writes word[0] = "J" to change Python into Jython. It gives an error. Why? Write a line that does give Jython.
Strings are fixed. We build a new string from the pieces that we want.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
A string cannot be changed in place. We cannot replace one character inside it.
Fix. Build a new string from parts: "J" + word[1:]. The slice word[1:] is ython, everything from position 1 to the end. Joined with "J", it gives Jython.
The original word is still Python.
Log in to join the discussion.
Loading…