Skip to Content
Python语言及其应用(第2版)
book

Python语言及其应用(第2版)

by Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from Python语言及其应用(第2版)
习题答案
457
>>> def test(func):
... def new_func(*args, **kwargs):
... print('start')
... result = func(*args, **kwargs)
... print('end')
... return result
... return new_func
...
>>>
>>> @test
... def greeting():
... print("Greetings, Earthling")
...
>>> greeting()
start
Greetings, Earthling
end
4.
定义异常
OopsException
。产生该异常,看看会发生什么。然后,编写代码,捕获该异
常并打印出
'Caught an oops'
>>> class OopsException(Exception):
... pass
...
>>> raise OopsException()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.OopsException
>>>
>>> try:
... raise OopsException
... except OopsException:
... print('Caught an oops')
...
Caught an oops
10
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程

Python技术基础视频教程

保罗·J·戴特尔
Python面向对象编程指南

Python面向对象编程指南

Posts & Telecom Press, Steven F. Lott

Publisher Resources

ISBN: 9787115586223