Output of Python Programs | Set 22 (Loops) Last Updated : 06 Sep, 2024 Comments Improve Suggest changes Like Article Like Report Prerequisite: LoopsNote: Output of all these programs is tested on Python3 1. What is the output of the following? Python mylist = ['geeks', 'forgeeks'] for i in mylist: i.upper() print(mylist) [‘GEEKS’, ‘FORGEEKS’].[‘geeks’, ‘forgeeks’].[None, None].Unexpected Output: 2. [‘geeks’, ‘forgeeks’]Explanation: The function upper() does not modify a string in place, it returns a new string which isn’t being stored anywhere. 2. What is the output of the following? Python mylist = ['geeks', 'forgeeks'] for i in mylist: mylist.append(i.upper()) print(mylist) [‘GEEKS’, ‘FORGEEKS’].[‘geeks’, ‘forgeeks’, ‘GEEKS’, ‘FORGEEKS’].[None, None].None of these Output: 4. None of theseExplanation:The loop does not terminate as new elements are being added to the list in each iteration. 3. What is the output of the following? Python i = 1 while True: if i % 0O7 == 0: break print(i) i += 1 1 2 3 4 5 6.1 2 3 4 5 6 7.error.None of these Output: 1. 1 2 3 4 5 6Explanation: The loop will terminate when i will be equal to 7. 4. What is the output of the following? Python True = False while True: print(True) break False.True.Error.None of these Output: 3. ErrorExplanation: SyntaxError, True is a keyword and it’s value cannot be changed. 5. What is the output of the following? Python i = 1 while True: if i % 3 == 0: break print(i) i + = 1 1 2 3.1 2.Syntax Error.None of these Output: 3. Syntax ErrorExplanation: SyntaxError, there shouldn’t be a space between + and = in +=. Comment More infoAdvertise with us A Abhishek Sharma 44 Follow Improve Article Tags : Misc Technical Scripter Python Python Programs Program Output loop Python-Output Loops & Control Structure +4 More Practice Tags : Miscpython Similar Reads Output of python program | Set 14 (Dictionary) Prerequisite: Dictionary Note: Output of all these programs is tested on Python31) What is the output of the following program? PYTHON3 D = dict() for x in enumerate(range(2)): D[x[0]] = x[1] D[x[1]+7] = x[0] print(D) a) KeyError b) {0: 1, 7: 0, 1: 1, 8: 0} c) {0: 0, 7: 0, 1: 1, 8: 1} d) {1: 1, 7: 2 3 min read Output of python program | Set 15 (Modules) Prerequisite: Regular Expressions Note: Output of all these programs is tested on Python3 1) Which of the options below could possibly be the output of the following program? PYTHON from random import randrange L = list() for x in range(5): L.append(randrange(0, 100, 2)-10) # Choose which of outputs 3 min read Output of Python program | Set 15 (Loops) Prerequisite - Loops in Python Predict the output of the following Python programs. 1) What is the output of the following program? Python x = ['ab', 'cd'] for i in x: i.upper() print(x) Output:['ab', 'cd']Explanation: The function upper() does not modify a string in place, but it returns a new stri 2 min read Output of Python program | Set 16 (Threads) 1) What is the output of the following program? Python import threading barrier = threading.Barrier(4) class thread(threading.Thread): def __init__(self, thread_ID, thread_name): threading.Thread.__init__(self) self.thread_ID = thread_ID self.thread_name = thread_name def run(self): print("Thre 3 min read Output of Python program | Set 17 Prerequisite - Tuples and Dictionaryin Python Predict the output of the following Python programs. 1.What is the output of the following program? Python numberGames = {} numberGames[(1,2,4)] = 8 numberGames[(4,2,1)] = 10 numberGames[(1,2)] = 12 sum = 0 for k in numberGames: sum += numberGames[k] pri 2 min read Output of Python Programs | Set 18 (List and Tuples) 1) What is the output of the following program? PYTHON L = list('123456') L[0] = L[5] = 0 L[3] = L[-2] print(L) a) [0, '2', '3', '4', '5', 0] b) ['6', '2', '3', '5', '5', '6'] c) ['0', '2', '3', '5', '5', '0'] d) [0, '2', '3', '5', '5', 0] Ans. (d) Explanation: L[0] is '1' and L[5] is '6', both of t 3 min read Output of Python Programs | Set 19 (Strings) 1) What is the output of the following program? PYTHON3 str1 = '{2}, {1} and {0}'.format('a', 'b', 'c') str2 = '{0}{1}{0}'.format('abra', 'cad') print(str1, str2) a) c, b and a abracad0 b) a, b and c abracadabra c) a, b and c abracadcad d) c, b and a abracadabra Ans. (d) Explanation: String function 3 min read Output of Python Programs | Set 20 (Tuples) Prerequisite: Tuples Note: The output of all these programs is tested on Python3 1. What will be the output of the following program? Python3 tuple = (1, 2, 3, 4) tuple.append( (5, 6, 7) ) print(len(tuple)) Options: 125Error Output: 4. ErrorExplanation: In this case an exception will be thrown as tu 2 min read Output of Python Programs | Set 21 (Bool) Prerequisite : Boolean Note: Output of all these programs is tested on Python31. What is the output of the code: Python3 print(bool('False')) print(bool()) False, TrueNone, NoneTrue, TrueTrue, False Output: 4. True, False Explanation: If the argument passed to the bool function does not amount to ze 2 min read Output of Python Programs | Set 22 (Loops) Prerequisite: LoopsNote: Output of all these programs is tested on Python3 1. What is the output of the following?Python mylist = ['geeks', 'forgeeks'] for i in mylist: i.upper() print(mylist) [âGEEKSâ, âFORGEEKSâ].[âgeeksâ, âforgeeksâ].[None, None].Unexpected Output: 2. [âgeeksâ, âforgeeksâ]Explana 2 min read Like