单选题 适中
#17012

执行以下Python代码,如果文件data.txt不存在,输出结果是? ( ) try : with open ( 'data.txt' , 'r' ) as…

执行以下Python代码,如果文件data.txt不存在,输出结果是? ( )

try:
    with open('data.txt', 'r') as f:
        content = f.read()
    print("File read successfully.")
except FileNotFoundError:
    print("File not found.")
except Exception as e:
    print("An error occurred : ", e)
未登录也能判分,登录后才会记录
答案与解析
正确答案:B
解析
文件不存在触发文件不存在异常,执行对应分支代码。