Output of Python Programs | Set 21 (Bool) Last Updated : 11 Jun, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 zero then the Boolean function returns true else it always returns false. In the above code, in first line ‘False’ is passed to the function which is not amount to 0. Therefore output is true. In the second line, an empty list is passed to the function bool. Hence the output is false.2. What is the output of the code: Python3 print(not(4>3)) print(not(5&5)) False, FalseNone, NoneTrue, TrueTrue, False Output: 1. False, False Explanation: The not function returns true if the argument is false, and false if the argument is true. Hence the first line of above code returns false, and the second line will also returns false.3. What is the output of the code: Python3 print(['love', 'python'][bool('gfg')]) lovepythongfgNone Output: 2. python Explanation: We can read the above code as print ‘love’ if the argument passed to the Boolean function is zero else print ‘python’. The argument passed to the Boolean function in the above code is ‘gfg’, which does not amount to zero and hence the output is: "python".4. What is the output of the code: Python3 mylist =[0, 5, 2, 0, 'gfg', '', []] print(list(filter(bool, mylist))) [0, 0, ][0, 5, 2, 0, 'gfg', '', []]Error[5, 2, 'gfg'] Output: 4. [5, 2, 'gfg'] Explanation: The code above returns a new list containing only those elements of the list mylist which are not equal to zero. Hence the output is: [5, 2, 'gfg'].5. What is the output of the code: Python3 if (7 < 0) and (0 < -7): print("abhi") elif (7 > 0) or False: print("love") else: print("geeksforgeeks") geeksforgeeksloveabhiError Output: 2. love Explanation: The code shown above prints the appropriate option depending on the conditions given. The condition which matches is (7>0), and hence the output is: "love". Comment More infoAdvertise with us A Abhishek Sharma 44 Follow Improve Article Tags : Misc Python Program Output Python-Output Practice Tags : Miscpython Similar Reads 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 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 Like