Computer Science
Find the errors. State reasons.
t = 'hello'
t[0] = "H"
Python String Manipulation
2 Likes
Answer
t[0] = "H"
will raise an error because strings in python are immutable, meaning we cannot change individual characters in a string after it has been created. Therefore, attempting to assign a new value to t[0] will result in an error.
Answered By
3 Likes
Related Questions
Find the errors. State reasons.
t = [1, "a", 9.2] t[0] = 6
Find the errors. State reasons.
t = [1, "a", 9.2] t[4] = 6
Find the errors. State reasons.
for Name in [Amar, Shveta, Parag] IF Name[0] = 'S': print(Name)
Assuming words is a valid list of words, the program below tries to print the list in reverse. Does it have an error ? If so, why ? (Hint. There are two problems with the code.)
for i in range(len(words), 0, -1): print(words[i], end=' ')