Python语言基础
Python语言进阶
Python数据结构

使用 else 定义代码块

使用 else 关键字定义没有出现错误时执行的代码块
以下实例为学习使用 else 关键字定义没有出现错误时执行的代码块,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
#The try block does not raise any errors, so the else block is executed:
try:
  print("Hello")
except:
  print("Something went wrong")
else:
  print("Nothing went wrong")
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com

Hello

Nothing went wrong

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4