osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Which part of the loop is it going through in this class frame?


On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote:

> class Clock(object):
>     def __init__(self, time):
>         self.time = time
>     def print_time(self):
>         time = '6:30'
>         print(self.time)
> 
> clock = Clock('5:30')
> clock.print_time()
> 5:30
> 
> I set time to 6:30, but it's coming out to 5:30. I guess it's because I
> passed in 5:30, so, it's replaced?

Hint:  in Python, self.time and time are not the same (unless you've
played some sort of weird trick somewhere).

Dan