Complete the code to create a new string by replacing the first character.
text = "hello" new_text = [1] + text[1:] print(new_text)
Strings must be enclosed in quotes. Using 'j' creates a new string starting with 'j'.
Complete the code to show that strings cannot be changed by assignment.
text = "hello" try: text[0] = [1] except TypeError: print("Cannot change string characters directly")
Assigning a new character to a string index requires a string in quotes.
Fix the error in the code that tries to change a string character.
word = "world" word = [1] + word[1:] print(word)
To create a new string with a changed first letter, use a quoted character and concatenate.
Fill both blanks to create a new string with the last character replaced.
word = "python" new_word = word[:[1]] + [2] print(new_word)
Use 5 to slice up to the last character (index 5), and '!' as the new last character.
Fill all three blanks to replace the middle character in a string.
word = "apple" new_word = word[:[1]] + [2] + word[[3]:] print(new_word)
Slice before index 2, add 'i' as a string, then slice from index 3 to end.