Hyun Jun Jung's Content

There have been 1 items by Hyun Jun Jung (Search limited from 17-December 16)


By content type

See this member's

Sort by                Order  

#129169 Chapter 6, Athlete Class Question

Posted by Hyun Jun Jung on 07 August 2015 - 10:20 PM in Head First Python

Hi I am having a strance trouble in Athlete class in chap6

 

I typed pretty much same as written in the book:

 

class Athlete:

 

   def __init__(self, a_name, a_dob = None,  a_times = []):

      self.name = a_name

      self.dob = a_dob

      self.times = a_times

 

   def add_time(self, time_value):

      self.times.append(time_value)

 

   def add_times(self, list_of_time):

      self.times.extend(list_of_times):

 

 

Yes.. It works fine.... However, as soon as I use method

add_time or add_times, its __init__ method is changed for no reason

 

before using the methods when I type

 

>>>help(Athlete)

...

__init__(self, a_name, a_dob = None, a_times = []) # It seems fine

...

 

 

however after use the methods

>>>jung = Athlete('jung')

>>>jung.add_time('1.11')

>>>help(Athlete)

...

__init___(self,  a_name, a_dob=None, a_times = ['1.11'])

...

 

init method is changed, so that whenever I create other Ahtlete class

 

>>john = Athlete('john')

>>john.times

['1.11']

 

even before I add anything to times, it has initial value which I used in add_time or add_times method before....

 

>>james = Athlete('james')

>>james.add_times(['1.05'])

>>kate = Athlete('kate')

>>kate.times

['1.11','1.05']

 

I don't know why this happening...





"