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版)
162
10
>>> def who_says(obj):
... print(obj.who(), 'says', obj.says())
...
>>> who_says(hunter)
Elmer Fudd says I'm hunting wabbits.
>>> who_says(hunted1)
Bugs Bunny says What's up, doc?
>>> who_says(hunted2)
Daffy Duck says It's rabbit season!
>>> who_says(brook)
Brook says Babble
这种行为有时被称作
鸭子类型
duck typing
),该名称源自以下这句俗语。
如果它像鸭子一样走路,像鸭子一样叫,那它就是一只鸭子。
——一位智者
我们有什么资格去争论关于鸭子的至理名言呢?图
10-1
是两只可爱的橡皮鸭。
10-1:鸭子类型可不是看着键盘打字(Duck typing is not hunt-and-peck
6
10.8
魔术方法
你现在已经能创建和使用基本对象了。本节所介绍的内容可能会让你大吃一惊(指好的
方面)。
6
typing
也有“打字”的意思。——译者注
对象和类
163
当输入像
a = 3 + 8
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