Python String Quiz Read Discuss Courses Python String Quiz Please wait while the activity loads. If this activity does not load, try refreshing your browser. Also, this page requires javascript. Please visit using a browser with javascript enabled. If loading fails, click here to try again Question 1Question 1: What is the output of the following program? str1 = '{2}, {1} and {0}'.format('a', 'b', 'c') str2 = '{0}{1}{0}'.format('abra', 'cad') print(str1, str2) c, b and a abracad0a, b and c abracadabraa, b and c abracadcadc, b and a abracadabraPython String Quiz Discuss itQuestion 1-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. Question 2Question 2: What is the output of the following program? a = 2 b = '3.77' c = -8 str1 = '{0:.4f} {0:3d} {2} {1}'.format(a, b, c) print(str1) 2.0000 2 -8 3.772 3.77 -8 3.772.000 3 -8 3.772.000 2 8 3.77Python String Quiz Discuss itQuestion 2-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 an integer, thus it remains to 2. Index 2 and 1 values are picked next, which are -8 and 3.77 respectively.Question 3Question 3: What is the output of the following program? line = "I'll come by then." eline = "" for i in line: eline += chr(ord(i)+3) print(eline) L*oo frph e| wkhq1L*oo#frph#e|#wkhq1l*oo@frph@e|$wkhq1O*oo#Frph#E|#wKhq1Python String Quiz Discuss itQuestion 3-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 an ASCII value of 32, thus it’ll become 35(‘#’), thus option (a) is ruled out as, ‘ ‘ cannot remain to be ‘ ‘ in the ciphered text.Question 4Question 4: What is the output of the following program? line = "What will have so will" L = line.split('a') for i in L: print(i, end=' ') [‘What’, ‘will’, ‘have’, ‘so’, ‘will’]Wh t will h ve so willWhat will have so will[‘Wh’, ‘t will h’, ‘ve so will’]Python String Quiz Discuss itQuestion 4-Explanation: split() will use ‘a’ as the delimiter. It’ll create partition 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.Question 5Question 5: What is the output of the following program? import string Line1 = "And Then There Were None" Line2 = "Famous In Love" Line3 = "Famous Were The Kol And Klaus" Line4 = Line1 + Line2 + Line3 print("And" in Line4) True 2TrueFalseFalse 2Python String Quiz Discuss itQuestion 5-Explanation: The "in" operator returns True if the string contains the substring (ie, And), else returns False.Question 6Question 6: What is the output of the following program? my_string = "geeksforgeeks" i = "i" while i in my_string: print(i, end =" ") geeksforgeeksNo Outputi i i i i i …g e e k s f o r g e e k s Python String Quiz Discuss itQuestion 6-Explanation: ‘i’ is not present in string ‘geeksforgeeks’Question 7Question 7: What is the output of the following program? my_string = 'geeksforgeeks' for i in range(my_string): print(i) 0 1 2 3 … 12geeksforgeeksNo OutputErrorPython String Quiz Discuss itQuestion 7-Explanation: range(str) is not allowed.Question 8Question 8: What is the output of the following program? my_string = 'geeksforgeeks' for i in range(len(my_string)): my_string[i].upper() print (my_string) GEEKSFORGEEKSgeeksforgeeksErrorNo OutputPython String Quiz Discuss itQuestion 8-Explanation: Changes do not happen in-place, rather it will return a new instance of the string.Question 9Question 9: What is the output of the following program? my_string = 'geeksforgeeks' for i in range(len(my_string)): print (my_string, end=" ") my_string = 'a' aaaaaaaaaaaageeksforgeeks a a a a a a a a a a a aErrorNo OutputPython String Quiz Discuss itQuestion 9-Explanation: String is modified only after ‘geeksforgeeks’ has been printed once.Question 10Question 10: What is the output of the following program? x = 123 for i in x: print(i, end=" ") 1 2 3 1 1 1ErrorNo OutputPython String Quiz Discuss itQuestion 10-Explanation: Objects of type int are not iterable instead a list, dictionary or a tuple should be used. 123 There are 21 questions to complete. You have completed questions question Your accuracy is Correct Wrong Partial-Credit You have not finished your quiz. If you leave this page, your progress will be lost. Correct Answer You Selected Not Attempted Final Score on Quiz Attempted Questions Correct Attempted Questions Wrong Questions Not Attempted Total Questions on Quiz Question Details Results Date Score Hint Time allowed minutes seconds Time used Answer Choice(s) Selected Question Text All doneNeed more practice!Keep trying!Not bad!Good work!Perfect! Last Updated : 28 Sep, 2023