Test Index
Python Revision Tour
© examsnet.com
Question : 97 of 102
Marks:
+1,
-0
Which of the following statement(s) would give an error after executing the following code ?
S="Happy" # Statement 1print(S*2) # Statement 2S+="Independence" # Statement 3S.append("Day") # Statement 4print(S) # Statement 5[CBSE 2023 Compartment]
Solution:
Concept:Strings are immutable and have no
append() method (append is a list method).Explanation:Statement 2: S*2 repeats the string, prints HappyHappy. Valid.Statement 3: S+="Independence" makes a new string and assigns it to S. Valid.Statement 4: S.append("Day") raises AttributeError: 'str' object has no attribute 'append'.So only Statement 4 gives an error.Answer:Option C (Statement 4)© examsnet.com
Go to Question: