469,610 Members | 1,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

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.append(argHire)
return self.myCrew

x = Organization("MyOrg", "JB", ["TL", "BK"])
print x.getName(), x.getLeader(), x.getCrew()
x.hireCrew("PD")
print x.getName(), x.getLeader(), x.getCrew()
Jul 18 '05 #1
4 1199
Hello Bill,
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.append(argHire)

The return value of list.append is None. However it does add the item to
the list. Try:
self.myCrew.append(argHire)

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

HTH.
Miki
Jul 18 '05 #2
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 <mi*********@zoran.com> wrote:

Hello Bill,
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.append(argHire)

The return value of list.append is None. However it does add the item to
the list. Try:
self.myCrew.append(argHire)

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

HTH.
Miki

Jul 18 '05 #3
In article <10*************@corp.supernews.com>, Bill wrote:
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?


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
Jul 18 '05 #4
Thank you!

David Lewis <Da************@SPAM.mac.com> wrote:

In article <10*************@corp.supernews.com>, Bill wrote:
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?


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

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Dream Catcher | last post: by
7 posts views Thread by berkay | last post: by
3 posts views Thread by Kriston-Vizi Janos | last post: by
5 posts views Thread by Little | last post: by
4 posts views Thread by Bucco | last post: by
10 posts views Thread by Ben | last post: by
2 posts views Thread by jeremito | last post: by
2 posts views Thread by Georgy Panterov | last post: by
12 posts views Thread by Samir | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.