题目
题目

Fal25_CS003C_74229 Ch. 7 Pre-Quiz (Remotely Proctored)

单项选择题

Python's error handling process includes the finally clause. In the following code snippet, when is the finally clause executed? inputFile = open("lyrics.txt", "r") try : line = inputFile.readline() words = line.split() print(words) finally : inputFile.close()

选项
A.The finally clause is never executed in this example.
B.Only when there is an error opening the file.
C.Only when there is an error reading the file.
D.The finally clause is always executed in this example.
查看解析

查看解析

标准答案
Please login to view
思路分析
To tackle this question, start by identifying where the try/finally structure sits and what it guarantees. Option 1: 'The finally clause is never executed in this example.' This would be true only if the code before the try block prevented reaching the finally, or if Python behaved differently; however, the purpose of finally is precisely to run after the try block completes, re......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!