Output of Python program | Set 17
Prerequisite – Tuples and Dictionaryin Python
Predict the output of the following Python programs.
- What is the output of the following program?
numberGames={}numberGames[(1,2,4)]=8numberGames[(4,2,1)]=10numberGames[(1,2)]=12sum=0forkinnumberGames:sum+=numberGames[k]printlen(numberGames)+sumchevron_rightfilter_noneOutput:
33
Explanation:
Tuples can be used for keys into dictionary. The tuples can have mixed length and the order of the items in the tuple is considered when comparing the equality of the keys. - What is the output of the following program?
my_tuple=(1,2,3,4)my_tuple.append( (5,6,7) )printlen(my_tuple)chevron_rightfilter_noneOutput:
Error !
Explanation:
Tuples are immutable and don’t have an append method as in case of Lists.Hence an error is thrown in this case. - What is the output of the following program?
t=(1,2)print2*tchevron_rightfilter_noneOutput:
(1, 2, 1, 2)
Explanation:
Asterick Operatr (*) operator concatenates tuple. - What is the output of the following program?
d1={"john":40,"peter":45}d2={"john":466,"peter":45}printd1 > d2chevron_rightfilter_noneOutput:
False
Explanation:
Arithmetic operator less than ( < ) or greater than ( > ) can be used with dictionaries and each corresponding key with its values are compared - What is the output of the following program?
my_tuple=(6,9,0,0)my_tuple1=(5,2,3,4)printmy_tuple > my_tuple1chevron_rightfilter_noneOutput:
True
Explanation:
Each elements of the tuples are compared one by one and if maximum number of elements are there in tuple1 which are greater of equal to corresponding element of tuple2 then tuple1 is said to be grater than tuple2.
This article is contributed by Avinash Kumar Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Output of Python Program | Set 1
- Output of Python program | Set 5
- Output of python program | Set 2
- Output of Python Program | Set 3
- Output of Python Program | Set 4
- Output of Python program | Set 6 (Lists)
- Output of Python program | Set 16 (Threads)
- Output of python program | Set 14 (Dictionary)
- Output of Python program | Set 15 (Loops)
- Output of python program | Set 15 (Modules)
- Output of python program | Set 11(Lists)
- Output of python program | Set 12(Lists and Tuples)
- Output of python program | Set 13(Lists and Tuples)
- Output of C Program | Set 29
- Output of C++ Program | Set 19



