最赞回答 / 慕函数7599421
假如<...code...>你可以推算def gcd(a, b)的过程(类似于for循环),得到两个数的最大公约数为3,这个3会在最终的结果中作为分母被除掉。没有没有def gcd(a, b)函数,那么我们得到的最终结果会有3/6,4/8这样的结果。
2022-01-24
最赞回答 / weixin_慕设计1349666
class Animal(): def __init__(self,name,age,location): self.__name=name self.__age=age self.__location=location def get_info(self): return 'name={},\nage={},\nlocation={}'.format(self.__name,self.__age,self.__location) ...
2022-01-07
最新回答 / hermaniu
Traceback (most recent call last): File "C:\Users\hermaniu\Desktop\test1.py", line 162, in <module> w=Work('Herman',96,'english',22) File "C:\Users\hermaniu\Desktop\test1.py", line 156, in __init__ super(Work,self).__init__(name,score,course...
2021-11-23
最赞回答 / 慕粉_pp
关于调用两种方法的时机使用print()时使用%s和f'{}'拼接对象时使用str(x)转换对象x时在上述三种场景中,会优先调用对象的__str__()方法;若没有,就调用__repr__()方法;若再没有,则显示其内存地址。特别地,对于下面两种场景:用%r进行字符串拼接时用repr(x)转换对象x时则会调用这个对象的__repr__()方法;若没有,则不再看其是否有__str__()方法,而是显示其内存地址。<...code...>
2021-11-20
最赞回答 / hermaniu
实例本身无count,get_count定义的是类方法,因此Leo.get_count()返回Animal的私有属性__count=0,set_count是实例方法对类无效,因此获取的__count 还是原本的0.
2021-11-18
最新回答 / 慕无忌1545359
class Animal(object): def __init(self,name,age,location): self.__name = name self.__age = age self.__location = location def set_name(self,name): self._name = name def get_name(self): return self...
2021-11-17