请问图中的plus(self,another)的作用是啥呀

m0_71316592 2023-10-18 20:50:32

如题,看不明白anther怎么用的,求教俺一下

 

 

 

...全文
114 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tanwjun 2023-10-19
  • 打赏
  • 举报
回复 1
  1. 在输出中,可以看出解释器把plus当成外部的函数,但它是类app的一个函数,需要指定指定对象后才能使用。
  2. another只是内部参数,不能在外部调用。
  3. 修改建议:
class app:
    def __init__(self, num, den) -> None:
        self.num = num
        self.den = den

    def plus(self, another):
        self.den = self.den * another.den
        self.num = self.den * another.num + another.den * self.num
        return app(self.num, self.den)


ap = app(2, 3)
another = app(4, 5)
ap = ap.plus(another)
print(ap.num, ap.den)
m0_71316592 2023-10-19
  • 举报
回复
@Tanwjun 谢谢你
Tanwjun 2023-10-21
  • 举报
回复
@m0_71316592 不用谢
he basic design and direction of this book is absolutely excellent. The question and answer format engages the reader for better understanding, and the topics covered include a wide variety of essential areas. The book falls down, however, because of being 'rushed out without adequate editing' (nor usable index), thus leaving the reader confused at times. Other problems include incorrect answers to problems, and inadequate explanations. So while I know that I learned a lot from the book, I also know that if I recommended it to friends they would be calling me saying how frustrated they were with the mistakes. For that very reason my review is not a recommendation. I have strong hopes that the next edition will fix the problems here and I will THEN be able to recommend this book. In case you are wondering (and I know I was), the third edition is actually written by Earl Boysen now since Harry Kybett, having written the first two editions, has passed away. The Q & A format is one of those things that always seems to be a bit unique in any particular book, and this one is no exception. In the early chapters many of the questions may seem insulting in that they are so easy, and the reader can find themself wondering if the book was written for 8 year old kids! But the real beauty of that approach is that it forces your mind to change modes on a regular basis: instead of staying in a passive info-absorbing mode, it has to stop and become active at solving a problem, which results in better retention. So even if the question seems childish, the information is more firmly impressed on you. In the middle and latter chapters, the Q & A format usually sticks with problem solving, often asking you to repeat the same sort of calculations you have seen in examples. Most of the time the solutions include more than just answers, serving to explain just how the answer was arrived at. But the problems occur with that word "most"! It is also the case that many of the times when we

11,952

社区成员

发帖
与我相关
我的任务
社区描述
创建由Python学习者和社区专家组成的国内最大的第三方Python中文社区,帮助社区成员更好地入门学习、职业成长和应用实践
python学习 企业社区
社区管理员
  • Python全栈技术社区
  • Lumos_zbj
  • 北侠大卫
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

创建由Python学习者和社区专家组成的国内最大的第三方Python中文社区,帮助社区成员更好地入门学习、职业成长和应用实践

  • 这里有最新最全的 Python 学习内容及资源,每月多达4次技术公开课
  • 这里有众多 Python 学习者,陪伴你一起交流成长
  • 这里有专业 Python 社区专家、讲师,帮助你跨越学习瓶颈,解决实操难题
  • 这里有丰富的社区活动,可以开阔眼界,结识更多同伴

【最新活动】:

  1. 周四技术公开课讲师招募中,点击查看详情
  2. “Python 社区专家团” 招募中,点击查看详情

 

试试用AI创作助手写篇文章吧