GPYC Exam QuestionsBrowse all questions from this exam

GPYC Exam - Question 17


What is the output of the following commands typed in the Python Interactive shell?

Show Answer
Correct Answer: D

In the given Python code, the try block executes without any exceptions occurring, so the corresponding 'except' block is not executed. Following the code logic, since no exception occurs, the 'else' block will be executed. Finally, regardless of whether an exception occurs or not, the 'finally' block will always execute. Therefore, the output will be the concatenation of the print statements from the 'try', 'else', and 'finally' blocks, which is 'Try Else Finally'.

Discussion

1 comment
Sign in to comment
AZIrvThoOption: D
Sep 29, 2023

When running this code: try: print ("Try", end=' ') except: print ("Except", end=' ') else: print ("Else", end=' ') finally: print ("Finally", end=' ') The response is "Try Else Finally"