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

Dan Sommers dan at tombstonezero.net
Wed Mar 7 21:10:19 EST 2018


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





More information about the Python-list mailing list