List append help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill

    List append help

    I am trying to do an exercise in an online tutorial that but the tutorial
    does not list the solution. Could someone please tell me why the "hireCrew"
    method in the following code leaves me with a list that contains "None"? Be
    nice, this is my first go at this, thanks!

    class Organization:
    def __init__(self, argName, argLeader, argCrew):
    self.myName = argName
    self.myLeader = argLeader
    self.myCrew = argCrew

    def getName(self):
    return self.myName

    def setLeader(self, argLeader):
    self.myLeader = argLeader

    def getLeader(self) :
    return self.myLeader

    def getCrew(self):
    return self.myCrew

    def hireCrew(self, argHire):
    self.myCrew = self.myCrew.app end(argHire)
    return self.myCrew

    x = Organization("M yOrg", "JB", ["TL", "BK"])
    print x.getName(), x.getLeader(), x.getCrew()
    x.hireCrew("PD" )
    print x.getName(), x.getLeader(), x.getCrew()
  • Miki Tebeka

    #2
    Re: List append help

    Hello Bill,
    [color=blue]
    > Could someone please tell me why the "hireCrew"
    > method in the following code leaves me with a list that contains "None"?
    > ...
    > self.myCrew = self.myCrew.app end(argHire)[/color]
    The return value of list.append is None. However it does add the item to
    the list. Try:
    self.myCrew.app end(argHire)

    On a side note, I find this `arg' prefix for an argument irritating :-)

    HTH.
    Miki

    Comment

    • Bill

      #3
      Re: List append help

      Thank you, This was really bugging me. To help me understand, do you know
      why the return value was None even though it was added to the list? Also, I
      don't like having to type "arg" on every other line neither, so I won't:-)

      Miki Tebeka <miki.tebeka@zo ran.com> wrote:[color=blue]
      >
      >Hello Bill,
      >[color=green]
      >> Could someone please tell me why the "hireCrew"
      >> method in the following code leaves me with a list that contains "None"?
      > > ...
      > > self.myCrew = self.myCrew.app end(argHire)[/color]
      >The return value of list.append is None. However it does add the item to
      >the list. Try:
      >self.myCrew.ap pend(argHire)
      >
      >On a side note, I find this `arg' prefix for an argument irritating :-)
      >
      >HTH.
      >Miki[/color]

      Comment

      • David Lewis

        #4
        Re: List append help

        In article <1058329gsgeq85 f@corp.supernew s.com>, Bill wrote:
        [color=blue]
        > Thank you, This was really bugging me. To help me understand, do you know
        > why the return value was None even though it was added to the list?[/color]

        It¹s a philosophical decision made throughout Python. When an operation
        is destructive (i.e. it changes the object on which it operates rather
        than returning a new, changed, object), it returns None to emphasize
        the point.

        Best,
        David

        Comment

        • Guest's Avatar

          #5
          Re: List append help

          Thank you!

          David Lewis <DavidMLewis.NO @SPAM.mac.com> wrote:[color=blue]
          >
          >In article <1058329gsgeq85 f@corp.supernew s.com>, Bill wrote:
          >[color=green]
          >> Thank you, This was really bugging me. To help me understand, do you know
          >> why the return value was None even though it was added to the list?[/color]
          >
          >It¹s a philosophical decision made throughout Python. When an operation
          >is destructive (i.e. it changes the object on which it operates rather
          >than returning a new, changed, object), it returns None to emphasize
          >the point.
          >
          >Best,
          > David[/color]

          Comment

          Working...