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 1
b) 15 2
c) (15, 2)
d) True 2
Explanation: ‘Were’ is at Index 15 in Line1, find() returns the index of substring if found in the string Line1. count() returns the total number of occurences of the substring. Line4 is concatenated string from Line1, Line2 and Line3. This code works well with Python v2.x, as some string functions are deprecated in Python v3.x.
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.
- Output of C++ programs | Set 29 (Strings)
- Output of Java Programs | Set 52 (Strings Class)
- Output of Python programs | Set 8
- Output of Python programs | Set 7
- Output of Python Programs | Set 22 (Loops)
- Output of Python Programs | (Dictionary)
- Output of Python Programs | Set 24 (Sets)
- Output of Python Programs | Set 21 (Bool)
- Output of Python programs | Set 9 (Dictionary)
- Output of Python Programs | Set 20 (Tuples)
- Output of Python Programs | Set 23 (String in loops)
- Output of Python programs | Set 10 (Exception Handling)
- Output of Python Programs | Set 18 (List and Tuples)
- Output of C programs | Set 51
- Output of C++ Programs | Set 49