CBSE Class 11 Computer Science
Question 45 of 91
String Manipulation — Question 5
Back to all questions 5
Question Question 5
Can you say strings are character lists? Why? Why not?
Answer
Strings are sequence of characters where each character has a unique index. This implies that strings are iterable like lists but unlike lists they are immutable so they cannot be modified at runtime. Therefore, strings can't be considered as character lists. For example,
str = 'cat'
# The below statement
# is INVALID as strings
# are immutable
str[0] = 'b'
# Considering character lists
strList = ['c', 'a', 't']
# The below statement
# is VALID as lists
# are mutable
strList[0] = 'b'