《Python核心编程》第二版第405页第十三章练习 -Python核心编程答案-自己做的-

这是自己做的练习,可能有错误,欢迎讨论和各种优化重构方案。

13-1.
程序设计。请列举一些面向对象编程与传统旧的程序设计形式相比的先进之处。
【答案】
面向对象编程(Object Oriented Programming,OOP,面向对象程序设计)是一种计算机编程架构。OOP的一条基本原则是计算机程序是由单个能够起到子程序作用的单元或对象组合而成。OOP达到了软件工程的三个主要目标:重用性、灵活性和扩展性。为了实现整体运算,每个对象都能够接收信息、处理数据和向其它对象发送信息。
【注】
答案摘抄自百度百科。

13-2.
函数和方法的比较。函数和方法之间的区别是什么?
Functions versus Methods. What are the differences between functions and methods?
【注】
在网上对这个问题有很多讨论(有的很有趣,比如提到猫和cat),如果用英文关键词搜索,答案亦很多。我的答案摘抄自本题【参考】部分的第一个链接。
【答案】
A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).

All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.

1. It is implicitly passed the object for which it was called

2. It is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data)

【参考】
http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function
http://www.wellho.net/mouth/900_Python-function-v-method.html

转载于:https://www.cnblogs.com/balian/archive/2012/08/31/2664931.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值