Output of Python Programs | Set 23 (String in loops) Last Updated : 14 Dec, 2017 Comments Improve Suggest changes Like Article Like Report Prerequisite: Loops and String Note: Output of all these programs is tested on Python3 1. What is the output of the following? Python3 my_string = "geeksforgeeks" i = "i" while i in my_string: print(i, end =" ") None geeksforgeeks i i i i i i … g e e k s f o r g e e k s Output: 1. None Explanation: 'i' is not present in string 'geeksforgeeks' 2. What is the output of the following? Python3 i = 0 while i < 3: print(i) i += 1 else: print(0) 0 1 2 3 0 0 1 2 0 0 1 2 Error Output: 2. 0 1 2 0 Explanation: The else part is executed when the condition in the while statement is false. 3. What is the output of the following? Python3 my_string = 'geeksforgeeks' for i in range(my_string): print(i) 0 1 2 3 ... 12 geeksforgeeks None Error Output: 4. Error Explanation: range(str) is not allowed. 4. What is the output of the following? Python3 my_string = 'geeksforgeeks' for i in range(len(my_string)): my_string[i].upper() print (my_string) GEEKSFORGEEKS geeksforgeeks Error None Output: 2. geeksforgeeks Explanation: Changes do not happen in-place, rather it will return a new instance of the string. 5. What is the output of the following? Python3 my_string = 'geeksforgeeks' for i in range(len(my_string)): print (my_string) my_string = 'a' gaaaaaaaaaaaa geeksforgeeks a a a a a a a a a a a a Error None Output: 2. geeksforgeeks a a a a a a a a a a a a Explanation: String is modified only after ‘geeksforgeeks’ has been printed once. Comment More infoAdvertise with us A Abhishek Sharma 44 Follow Improve Article Tags : Misc Technical Scripter Python Program Output Python-Output Loops & Control Structure +2 More Practice Tags : Miscpython Similar Reads 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 Output of Python Programs | Set 23 (String in loops) Prerequisite: Loops and String Note: Output of all these programs is tested on Python3 1. What is the output of the following? Python3 my_string = "geeksforgeeks" i = "i" while i in my_string: print(i, end =" ") None geeksforgeeks i i i i i i ⦠g e e k s f o r g e e k s 2 min read Like