Computer Science
If you give the following for str1 = "Hello", why does Python report error?
str1[2] = 'p'
Python Data Handling
20 Likes
Answer
Python reports error because strings are immutable and hence item assignment is not supported.
Answered By
13 Likes
Related Questions
Two objects (say a and b) when compared using == ,return True. But Python gives False when compared using is operator. Why? (i.e., a == b is True but why is a is b False?)
What will the result given by the following?
(a) type (6 + 3)
(b) type (6 -3)
(c) type (6 *3)
(d) type (6 / 3)
(e) type (6 // 3)
(f) type (6 % 3)
What are augmented assignment operators? How are they useful?
Given str1 = "Hello", what will be the values of:
(a) str1[0]
(b) str1[1]
(c) str1[-5]
(d) str1[-4]
(e) str1[5]