Output of Python Programs | Set 20 (Tuples) Last Updated : 26 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 tuples are immutable and don’t have an append method. 2. What will be the output of the following program ? Python3 tuple = {} tuple[(1,2,4)] = 8 tuple[(4,2,1)] = 10 tuple[(1,2)] = 12 _sum = 0 for k in tuple: _sum += tuple[k] print(len(tuple) + _sum) Options: 34123133 Output: 4. 33Explanation: Tuples can be used for keys into dictionary. The tuples can have mixed lengths and the order of the items in the tuple is considered when comparing the equality of the keys. 3. What will be the output of the following program ? Python3 tuple1 = (1, 2, 4, 3) tuple2 = (1, 2, 3, 4) print(tuple1 < tuple2) Options: ErrorTrueFalseUnexpected Output: 3. FalseExplanation: In this case elements will be compared one by one. So, when it compares 4 with 3 it will return False. 4. What will be the output of the following program ? Python3 tuple = (1, 2, 3) print(2 * tuple) Options: (1, 2, 3, 1, 2, 3)(1, 2, 3, 4, 5, 6)(3, 6, 9)Error Output: 1. (1, 2, 3, 1, 2, 3)Explanation: '*' operator is used to concatenate tuples. 5. What will be the output of the following program ? Python3 tuple=("Check")*3 print(tuple) Options: Unexpected(3Check)CheckCheckCheckSyntax ErrorOutput: 3. CheckCheckCheckExplanation: Here “Check” will be treated as is a string not a tuple as there is no comma after the element. Comment More infoAdvertise with us A Abhishek Sharma 44 Follow Improve Article Tags : Python Python-Output python-tuple Practice Tags : python Similar Reads Output of python program | Set 12(Lists and Tuples) Prerequisite: List and Tuples Note: Output of all these programs is tested on Python3 1) What is the output of the following program? PYTHON L1 = [] L1.append([1, [2, 3], 4]) L1.extend([7, 8, 9]) print(L1[0][1][1] + L1[2]) a) Type Error: can only concatenate list (not "int") to list b) 12 c) 11 d) 3 3 min read Output of python program | Set 13(Lists and Tuples) Prerequisite: Lists and Tuples1) What is the output of the following program? PYTHON List = [True, 50, 10] List.insert(2, 5) print(List, "Sum is: ", sum(List)) a) [True, 50, 10, 5] Sum is: 66 b) [True, 50, 5, 10] Sum is: 65 c) TypeError: unsupported operand type(s) for +: 'int' and 'str' d) [True, 5 3 min read 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 Like