Why getId method doesn't work

I have copied some codes as below.

class Person(object): 
   def __init__(self, family_name, first_name): 
      self.family_name = family_name 
      self.first_name = first_name 
    def familyName(self): 
       return self.family_name 
   def firstName(self): 
       return self.first_name 
   def __str__(self): 
      return '<Person: %s %s>'%(self.first_name, self.family_name) 
class MITPerson(Person): 
   nextIdNum = 0 
   def __init__(self, familyName, firstName): 
     Person.__init__(self, familyName, firstName)
     self.idNum = MITPerson.nextIdNum
     MITPerson.nextIdNum += 1 
   def getIdNum(self): 
     return self.idNum 
   def __str__(self): 
     return '<MIT Person: %s %s>'%(self.first_name, self.family_name) 
   def __cmp__(self,other): 
     return self.idNum == other.idNum

MIT2 = MITPerson("Wang","Jean")
id = MIT2.getIdNum

When I try to run the print(id0, I got the message below:
<bound method MITPerson.getIdNum of <main.MITPerson object at 0x7f0cbd112250>>

Why the id is not printed out?

getIdNum is a method. You’re not calling it, you’re just getting a reference to the method itself.

That line should be:

id = MIT2.getIdNum()
1 Like

Thanks~, Matthew. I will try to keep the syntax in mind next time.