1) What is the output of the following program?
a) c, b and a abracad0
b) a, b and c abracadabra
c) a, b and c abracadcad
d) c, b and a abracadabra
Explanation: String function format takes a format string and an arbitrary set of positional and keyword arguments. For str1 ‘a’ has index 2, ‘b’ index 1 and ‘c’ index 0. str2 has only two indices 0 and 1. Index 0 is used twice at 1st and 3rd time.
2) What is the output of the following program?
a) 2.0000 2 -8 3.77
b) 2 3.77 -8 3.77
c) 2.000 3 -8 3.77
d) 2.000 2 8 3.77
Explanation: At Index 0, integer a is formatted into a float with 4 decimal points, thus 2.0000. At Index 0, a = 2 is formatted into a integer, thus it remains to 2. Index 2 and 1 values are picked next, which are -8 and 3.77 respectively.
3) What is the output of the following program?
a) True 2
d) False 2
The “in” operator returns True if the strings contains the substring (ie, And), else returns False.
4) What is the output of the following program?
a) L*oo frph e| wkhq1
Explanation: This piece of code ciphers the plain text. Each character is moved to its 3rd next character by increasing the ascii value. ‘I’ becomes ‘L’, thus option (c) and (d) are ruled out. ‘ ‘ has ascii value of 32, thus it’ll become 35(‘#’), thus option (a) is ruled out as, ‘ ‘ can not remain to be ‘ ‘ in the ciphered text.
5) What is the output of the following program?
a) [‘What’, ‘will’, ‘have’, ‘so’, ‘will’]
b) Wh t will h ve so will
c) What will have so will
d) [‘Wh’, ‘t will h’, ‘ve so will’]
Explanation: split() will use ‘a’ as the delimiter. It’ll create parition at ‘a’, thus split() return an array L, which is in [‘Wh’, ‘t will h’, ‘ve so will’]. For loop will print the elements of the list.
This article is contributed by Piyush Doorwar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.