当前位置: 首页 > 图灵资讯 > 行业资讯> python finally语句如何使用

python finally语句如何使用

发布时间:2024-07-30 09:57:23

说明

1、finally语句中的代码执行,无论try中是否有异常。finally子句是try语句结束前的最后任务。

2、如果finally句包含return句,则返回值来自finally句的return句的返回值,而不是try句的return句的返回值。

实例

>>>defbool_return():
...try:
...returnTrue
...finally:
...returnFalse
...
>>>bool_return()
False

以上是python 使用finally语句,希望对大家有所帮助。更多Python学习指导:python基础教程

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09