Class 11 Computer Science String Manipulation Check Point 10.1 Sumita Arora Solution
Check Point 10.1
Que 1. How are strings internally stored?
Ans: Internally strings are stored as an ordered set of characters inside the single quote. Each character is having individual index position as per their order.
Que 2. For a string s storing ‘Goldy’, what would s[0] and s[-1] return?
Ans: s[0] => ‘G’ and s[-1] => ‘y’
Que 3. The last character of a string s is at index len(s) – 1. True/False
Ans: True
Que 4. For strings, + means (1); * means (2). Suggest words for position (1) and (2).
Ans: (1) + means Concatenation and (2) * means repetition or replication
Que 5. Given that s1 = “spam” s2 = “ni !” What is the output produced by following expressions? (a) ” The Knights who say, “+ s2 (b) 3 * s1 + 2 * s2 (c) s1[1]
Ans: (a) ‘The Knights who say, ni !’ (b) ‘spamspamspamni !ni!’ (c) ‘p’
Que 6. What are membership operators? What do they basically do?
Ans: Membership operators are used to check the existence of a substring inside the another string i.e. check the substring is the member of a string or not.
Two types of membership operators: (a) in – returns True if found the substring inside the string, otherwise returns False.
(b) not in – returns True if not found the substring inside the string, otherwise returns False.
Que 7. On what principles, the strings are compared in Python?
Ans: Strings are compared in Python based on the standard character by character rules for as per their ordinal number (i.e. unicode number or dictionary order).
Que 8. What will be the result of following expressions? (a) “Wow Python” [1] (b) “Strings are fun.”[5] (c) len(“awesome”) (d) “Mystery”[:4] (e) “apple” > “pineapple” (f) “pineapple” < “Peach” (g) “cad” in “abracadabra” (h) “apple” in “Pineapple” (i) “pine” in “Pineapple”
Ans: String slices means extracting the substring (parts of) from the string. Syntax: string[start_index : stop_index : step_value] where step_value is optional, by default its value is 1.
Que 10. Considering the same strings s1 and s2 of question 5 above, evaluate the following expressons: (a) s1[1:3] (b) s1[2] + s2[: 2] (c) s1 + s2[-1] (d) s1[ : 3] + s1[3 : ] (e) s2[ : -1] + s2[-1 : ]
Ans: Value of s1 and s2, as given in question number 5, are s1 = “spam” s2 = “ni !” (a) ‘pa’ (b) ‘ani’ (c) ‘spam!’ (d) ‘spam’ (e) ‘ni !’