类
ax1971
这个作者很懒,什么都没留下…
展开
-
2021-08-22循环迭代器
class MyIteration: def __init__(self,bejin,end): self.bejin = bejin self.end = end def __iter__(self): return self def __next__(self): if self.bejin == self.end: raise StopIteration('停止') x原创 2021-08-22 21:32:24 · 57 阅读 · 0 评论 -
查看一个类是否可迭代
class MyIteration: def __iter__(self): pass inter_obj = MyIteration() from _collections_abc import Iterable result = isinstance(inter_obj,Iterable) print(result)原创 2021-08-22 21:29:54 · 75 阅读 · 0 评论 -
python模拟简单计算器
模拟简单的计算器。 a. 定义名为Number的类,其中有两个整型数据对象n1和n2,声明为公有。编写初始化方 法,赋予n1和n2初始值,再为该类定义加(addition)、减(subtration)、乘 (multiplication)、除(division)等公有对象方法,分别对两个属性执行加、减、 乘、除的运算。 b. 创建Number类的对象,调用各个方法,并显示计算结果。 class Number: n1 = 0 n2 = 0 def calculation(self,原创 2021-07-31 17:46:12 · 3305 阅读 · 1 评论