Exam GPYC All QuestionsBrowse all questions from this exam
Question 17

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

    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
AZIrvThoOption: D

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"