Apr-05-2020, 06:24 AM
Here, may i know why when i use
Peter.dictthe following error will occur
Error:Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Celsius' object has no attribute 'dict'
But when i usePeter.__dict__It will work. What's the difference? Many thanks.
class Celsius: def __init__(self, temperature = 0): self.temperature = temperature def to_fahrenheit(self): return (self.temperature * 1.8) + 32 Peter = Celsius() Peter.temperature = 37 Peter.__list__